Search code examples
angularngx-datatable

How to sort angular ngx datatable with specific criteria


I am developing a table view with angular, ngx datatable where I have few columns that can be sorted. For example I have a column called "full prize" which shows addition of two fields which are row.price1 and row.price2. When I click on column name, I want to sort the table according to full prize. But since the full prize value is a calculated one, I cannot achieve it directly.

<ngx-datatable-column name="full price" prop="price1">

<ng-template let-row="row" ngx-datatable-cell-template>

{{row.price1+ row.price2}}

</ng-template>

</ngx-datatable-column>

Above given is the way to sort with price1. But how to sort with full prize?.

Can anyone help on this. Thank you.


Solution

  • You can pass a custom comparator function for the column https://swimlane.gitbook.io/ngx-datatable/api/column/inputs#comparator