3

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.

KARTHIKEYAN.A
  • 18,210
  • 6
  • 124
  • 133
Shardul
  • 90
  • 1
  • 9

4 Answers4

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
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
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