Search code examples
javascriptsortingag-gridag-grid-angularag-grid-react

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


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.


Solution

  • 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"}
    ]