ag-grid: Getting list of columns on which sorting is applied

8.8k Views Asked by At

How do I get the list of columns on which sorting is applied, in ag-grid. There is an api (onSortChanged) and an event (sortChanged). But neither is helpful in this scenario.

4

There are 4 best solutions below

1
On BEST ANSWER

You can use gridApi.getSortModel(), which returns you an array containing all column Ids and sort direction like below.

[
 {colId: "country", sort: "asc"},
 {colId: "athlete", sort: "asc"}
]
0
On

You can check the status of particular grid column - sort status etc using :-

params.columnApi.getColumnState();

The default value is null. "asc" or "desc" are other sort status.

0
On

You can find in the following way

const listOfSortModel = gridParams.columnApi.getColumnState().filter(s => s.sort !== null)
0
On

AG Grid: as of version 24.0.0, getSortModel() is deprecated, sort information is now part of Column State. Use columnApi.getColumnState() instead.