Search code examples
angularprimengprimeng-datatablecolumnsorting

How to sort a particular column of prime-ng datatable using custom sorting algorithm


I am working on an older project which uses prime-ng's p-datatable. The table currently has default sorting on one column. Now I need to implement sorting on another column but that has to be a custom-logic based sorting.

I tried searching for the ways to do that but found that p-datatable provides this feature only on table level and not on column level as shown below:

<p-dataTable [value]="dataList" (onSort)="sortColumn()>

Also, I could not find the official documentationpage for p-datatable. Apparently it has been deprecated in favour of Turbotable.

Can someone please guide me the way of achieving the sorting on new column while keeping the sorting on original column intact.

Edit: If someone has a link to original p-datatable documentation, please share the same.

Thanks


Solution

  • You could do something like

    <p-column field="abc"  header="ABC" [sortable]="true" sortable="custom" (sortFunction)="buildSort($event)">
    

    Your sorting logic will go inside buildSort function. the event object will have the details of column and sort value.