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
getRowsfunction receives aparamsprop of typeIServerSideGetRowsParamscontaining arequestprop - this is of type
IServerSideGetRowsRequest, which describes current grid state, and includessortModel
SSRM - Sorting
- This example has 2 columns with Sorting -
Gold(Desc) andSilver(Desc) - Our mock server picks up the sorting in the
sortModelobject 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
getAdaptableSortStatefunction in State API returns anAdaptableSortStateobject - It contains details of all Custom Sort objects (and Custom Sort Comparers) used by currently sorted Columns
SSRM - Custom Sorting
- This example we sort the Grid via the
SportColumn - 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