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.
Asked
Active
Viewed 6,498 times
4 Answers
12
AG Grid: as of version 24.0.0, getSortModel()
is deprecated, sort information is now part of Column State. Use columnApi.getColumnState()
instead.

BSMP
- 4,596
- 8
- 33
- 44

Adul Moolkhuntod
- 121
- 1
- 3
4
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"}
]

Paritosh
- 11,144
- 5
- 56
- 74
-
Yeah. That's it. Thank you very much. – Shardul Oct 09 '20 at 13:36
3
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.

Mahi
- 3,748
- 4
- 35
- 70
2
You can find in the following way
const listOfSortModel = gridParams.columnApi.getColumnState().filter(s => s.sort !== null)

KARTHIKEYAN.A
- 18,210
- 6
- 124
- 133