AG-GRID Default Sort Model with Dynamic Column Defs

Viewed 13089

So I have a Grid setup that works with the Enterprise Row Model. The columns are very dynamic and so the column defs are not known until the first query for rows is made to the server. This all works fine, but how can I set a default sort state when the column defs are not set until after the request has succeeded?

3 Answers

Adding a sort attribute to your colDef works too.

Example:

const columnDefs = [
  {
    headerName: 'Created Date',
    field: 'CreateDate',
    sort: 'desc',
    sortingOrder: ['desc','asc'] //optional but for better sorting behaviour
  }
]

Try this

const sort = [
  {
    colId: "firstName",
    sort: "asc",
  },
  {
    colId: "lastName"
  },
];

this.gridApi.setSortModel(sort);
Related