Server-Side Row Model - Sorting

Summary

  • Column Sorting information is included by AG Grid in the request object sent to the server to enable server sorting
  • If using Custom Sorts, this request object, will need to be updated accordingly

When using the Server-Side Row Model, AG Grid will not perform any sorting.

Instead AG Grid hands that off to developers to perform on the server.

This is done using the standard getRows function in the custom IServerSideDatasource implementation, which can access a sortModel object that provides details of the current sorting in the Grid.

Note

  • the getRows function receives a params prop of type IServerSideGetRowsParams containing a request prop
  • this is of type IServerSideGetRowsRequest, which describes current grid state, and includes sortModel
SSRM - Sorting
Fork
  • This example has 2 columns with Sorting - Gold (Desc) and Silver (Desc)
  • Our mock server picks up the sorting in the sortModel object and updates the SQL it creates accordingly (using "OrderBy")

Custom Sorts

There is one potential "gotcha" when sorting with the Server-Side Row Model.

The sortModel object has details of all Column Sorts in the Grid, but is not aware of any Custom Sorts.

Accordingly, it might be necessary to supplement the sortModel with any active Custom Sorts.

Hint

  • The useful getAdaptableSortState function in State API returns an AdaptableSortState object
  • It contains details of all Custom Sort objects (and Custom Sort Comparers) used by currently sorted Columns
SSRM - Custom Sorting
Fork
  • This example we sort the Grid via the Sport Column
  • We have also added a Custom Sort for this column which orders it 'Tennis', 'Cycling', 'Gymnastics' (and then alphabetically)
  • We updated the Request we send to our mock server with this new Sort - which is then acted upon by the mock server and reflected in the data it sends back
Try It Out
  • Scroll down the grid and notice how the Sport column is sorted using the Custom Sort