Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ag-Grid How to prevent default sort and filter?

I am using Client-side Row Model for aggrid, but i want to sort and filter by server-side, I don't know how to prevent the behavior of sort and filter by aggrid itself.

like image 877
Chao Jiang Avatar asked Dec 14 '25 13:12

Chao Jiang


1 Answers

For the sorting: I am having the same issue, I did a simple trick by using a mock sort comparator.

Add to each column object in columnsDefs array a "comparator" property returning 0 like:

columnDefs = columnDefs.map(colDef => ({
   ...colDef,
    comparator: () => 0
}));

In this way we say that the custom sorting comparator returns the same data, so you can still get benefit from the sorting icons.

Moreover, and in order to get the sorted data from the server, you just need to listen to sort change event like:

(sortChanged)="onSortChanged($event)"

Then in onSortChanged:

onSortChanged(event){
    const sortModel = this.gridApi.getSortModel();
    service.getDataFromServer(sortModel);
    refreshGrid(); // If needed
}
like image 53
hsenbassam Avatar answered Dec 16 '25 23:12

hsenbassam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!