1

I want to sort multiple columns at a time programatically. I am NOT using the default sorting method which is to click on header name to sort and ctrl/shift key + header name to sort multiple columns. I have a different option in the column options menu which is used to sort that specific column. For single column sort, I am using the following api.

params.api.setSortModel([
        {
          colId: params.column.colId,
          sort: "asc",
        }

Is there any api or anyway to sort multiple columns?

1 Answer 1

4

You need to construct a sortModel object which looks like this -

 var sortModel =    [
      {
        "colId": "athlete",
        "sort": "desc"
      },
      {
        "colId": "country",
        "sort": "asc"
      }
    ]

Then you can use the sorting api, the way you have used it and pass this model which is just an array containing more than one column instead of single column the way you have it in question

params.api.setSortModel(sortModel);

Example on sorting api.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi @Pratik Bhat. Thanks for your instant solutions and help. I have a few more questions regarding ag-grid. I will leave the links below, can you please answer if you know any solutions. stackoverflow.com/questions/61821748/… stackoverflow.com/questions/61825028/… stackoverflow.com/questions/61908211/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.