How to disable sorting on client after sorting on Server API?

Viewed 386

I have a DataGrid that when I click in a header column to sort(by Date for an example), it requests for my API that answer all the Data in the correct order. But after this, when Datagrid reload with the new Data, the Ag-Grid Component sort the column again, and it brings an incorrect order.

Is there a way to disable only the Sorting on Ag-Grid Component, but without disable the Header Sorting button(Because this button that sends the request to the API)?

2 Answers

Use a custom Comparator which does nothing. AG Grid, if no comparator is provided then uses alphabetical or numerical sort on fields but if you provide custom implementation of Comparator then it uses that to sort the data. since you are already sorting it on server thus you can use this

    var columnDefs = [
    { field: 'customField', comparator: customComparator},
    ....
    ];

    function customComparator(data1, data2) {
    return 0; //means no comparing and no sorting
    }
  1. Remove sortable (or)
  2. Use sortType = null

This can be done in ColumnDef.

Related