Server-Side Sorting

This section covers Server-Side Sorting using the Server-Side Row Model.

Enabling Sorting

Sorting is enabled in the grid via the sortable column definition attribute. Some example column definitions with sorting enabled are shown below:

gridOptions: { columnDefs: [ { field: 'country', sortable: true }, { field: 'year', sortable: true }, { field: 'sport' }, ], // other options }

For more details on sorting configurations see the section on Row Sorting.

Sorting on the Server

The actual sorting of rows is performed on the server when using the Server-Side Row Model. When a sort is applied in the grid a request is made for more rows via getRows(params) on the Server-Side Datasource. The supplied params includes a request containing sort metadata contained in the sortModel property.

An example of the contents contained in the sortModel is shown below:

//IServerSideGetRowsRequest { sortModel: [ { colId: 'country', sort: 'asc' }, { colId: 'year', sort: 'desc' }, ], // other properties }

Notice in the snippet above that the sortModel contains an array of models for each column that has active sorts in the grid. The column ID and sort type can then be used by the server to perform the actual sorting.

Example: Server-Side Sorting

The example below demonstrates server-side sorting. Notice the following:

  • Try single / multi column (using Shift key) sorting by clicking on column headers.
  • All columns have sorting enabled using the defaultColDef grid options property with sortable=true.
  • The server uses the metadata contained in the sortModel to sort the rows.
  • Open the browser's dev console to view the sortModel supplied in the request to the datasource.

Fake Server Implementation

Most of the Server-Side Row Model examples include a fake server that generates SQL to imitate how a real server might use the requests sent from the grid. These examples use AlaSQL which is a JavaScript SQL database that works in browsers.

However, note that the Server-Side Row Model does not impose any restrictions on the server-side technologies used.

Next Up

Continue to the next section to learn about Server-Side Filtering.