4

We have a PrimeNg datatable that has multiple columns (as most do), we need to be able to have a multiple sort happen when a user clicks on one of the 3 columns, but that column is only the first of two fields that it needs to sort on. The second field is a hidden field that will always be sorted ASC.

We have tried using multiSortMeta, multisort and sortfunctions, but are unable to get this working correct. Searching online, have only been able to find a single example of a sortFunction, but it is only for a single field.

Here is an example setup from the showcase, with some of the multisort stuff indicated.

<p-dataTable [value]="cars" multiSortMeta="multiSortMeta">
    <p-column field="vin" header="Vin"></p-column>
    <p-column field="year" header="Year"></p-column>
    <p-column field="brand" header="Brand" (sortFunction)="mySort($event)"></p-column>
    <p-column field="color" header="Color" (sortFunction)="mySort($event)"></p-column>
</p-dataTable>

How would you write the mySort function and/or change the dataTable definition to allow the user to click on the Color or Brand columns and have it sort by that field first, and the Year field second?

Any help would be greatly appreciated, as we are at our wits end trying to get this to work.

BillF
  • 804
  • 10
  • 20
  • Does anyone have any ideas on this? – BillF Jul 26 '17 at 15:52
  • I have same issue. I use multisort on 2 columns. When user clicks 3rd column I need to sort based on 3rd column. I wrote code and I am able to sort my itemssource collection. But primeng p-datatable is not reflecting it... – Ziggler Jan 10 '18 at 17:25

0 Answers0