This section covers Server-Side Sorting using the Server-Side Row Model.
Sorting is enabled in the grid via the sortable
column definition attribute.
<ag-grid-angular
[columnDefs]="columnDefs"
/* other grid options ... */>
</ag-grid-angular>
this.columnDefs = [
{ field: 'country', sortable: true },
{ field: 'year', sortable: true },
{ field: 'sport' },
];
For more details on sorting configurations see the section on Row Sorting.
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 request object sent to the server contains sort metadata in the sortModel
property, an example is shown below:
// Example request with sorting info
{
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.
The example below demonstrates sorting using the SSRM. Note the following:
defaultColDef.sortable = true
.sortModel
to sort the rows.sortModel
supplied in the request to the datasource.Continue to the next section to learn about SSRM Filtering.