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>
p-table sort with subfields
-
- Posts: 449
- Joined: 08 Aug 2018, 14:09
Hi,rootspain wrote: ↑25 Jun 2019, 10:36How 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>
Can you provide stackblitz sample using with https://stackblitz.com/github/primeface ... e-template .
Thanx for your attention.yigitfindikli wrote: ↑01 Jul 2019, 09:57Hi,
Can you provide stackblitz sample using with https://stackblitz.com/github/primeface ... e-template .
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.
-
- Posts: 449
- Joined: 08 Aug 2018, 14:09
Glad to hear, always happy to help!rootspain wrote: ↑24 Jul 2019, 08:50Thanx for your attention.yigitfindikli wrote: ↑01 Jul 2019, 09:57Hi,
Can you provide stackblitz sample using with https://stackblitz.com/github/primeface ... e-template .
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.
Best Regards.
-
- Information
-
Who is online
Users browsing this forum: Google [Bot] and 15 guests