p-table sort with subfields

UI Components for Angular
Post Reply
rootspain
Posts: 20
Joined: 14 Jun 2016, 13:57

25 Jun 2019, 10:36

How can I fix sort disability for p-table subfields?

<p-table [columns]="cols" [value]="list" selectionMode="single" [scrollable]="true" dataKey="id">
<ng-template pTemplate="colgroup" let-columns>
<colgroup>
<col *ngFor="let col of columns" style="width:200px">
</colgroup>
</ng-template>
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" [pSortableColumn]="col.field" >
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr [pSelectableRow]="rowData">
<td *ngFor="let col of columns">
<div *ngIf="col.subfield;then nested_object_content else normal_content"></div>
<ng-template #nested_object_content>
{{rowData[col.field][col.subfield]}}
</ng-template>
<ng-template #normal_content>
{{rowData[col.field]}}
</ng-template>
</td>
</tr>
</ng-template>
</p-table>

yigitfindikli
Posts: 449
Joined: 08 Aug 2018, 14:09

01 Jul 2019, 09:57

rootspain wrote:
25 Jun 2019, 10:36
How can I fix sort disability for p-table subfields?

<p-table [columns]="cols" [value]="list" selectionMode="single" [scrollable]="true" dataKey="id">
<ng-template pTemplate="colgroup" let-columns>
<colgroup>
<col *ngFor="let col of columns" style="width:200px">
</colgroup>
</ng-template>
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" [pSortableColumn]="col.field" >
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr [pSelectableRow]="rowData">
<td *ngFor="let col of columns">
<div *ngIf="col.subfield;then nested_object_content else normal_content"></div>
<ng-template #nested_object_content>
{{rowData[col.field][col.subfield]}}
</ng-template>
<ng-template #normal_content>
{{rowData[col.field]}}
</ng-template>
</td>
</tr>
</ng-template>
</p-table>
Hi,
Can you provide stackblitz sample using with https://stackblitz.com/github/primeface ... e-template .

rootspain
Posts: 20
Joined: 14 Jun 2016, 13:57

24 Jul 2019, 08:50

yigitfindikli wrote:
01 Jul 2019, 09:57
Hi,
Can you provide stackblitz sample using with https://stackblitz.com/github/primeface ... e-template .
Thanx for your attention.
We solved this by adding virtual field in columns model with concatinated values nested object name and nested field to identify which column is sorting. In my case many nested object have same field "name", but in sort function it was not possible to determine witch one exactly user sorting.

yigitfindikli
Posts: 449
Joined: 08 Aug 2018, 14:09

24 Jul 2019, 15:42

rootspain wrote:
24 Jul 2019, 08:50
yigitfindikli wrote:
01 Jul 2019, 09:57
Hi,
Can you provide stackblitz sample using with https://stackblitz.com/github/primeface ... e-template .
Thanx for your attention.
We solved this by adding virtual field in columns model with concatinated values nested object name and nested field to identify which column is sorting. In my case many nested object have same field "name", but in sort function it was not possible to determine witch one exactly user sorting.
Glad to hear, always happy to help!
Best Regards.

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 15 guests