docs

Sorting

The OData V4 model supports server-side sorting on lists.

To use server-side sorting, set the operation mode to sap.ui.model.odata.OperationMode.Server, as described in Filtering.

ODataListBinding allows to set static and dynamic sorters:

Dynamic sorters are transformed to an OData $orderby system query option value, and the static sorters are always appended as secondary sort criterion. In the example below, the equipments are first ordered by CategoryID (dynamic sorter that can be overwritten by calling sort on the list binding, Line 8) and then by Name (secondary sort criterion, static sorter, Line 6). For information on the optional group property (Line 10), see Sorting, Grouping, and Filtering for List Binding and Tree Bindingand the vGroup parameter of sap.ui.model.Sorter.

If additional properties need to be loaded in the context of a sorter — for example, for grouping — you can specify them via the groupPaths parameter of sap.ui.model.Sorter. With autoExpandSelect enabled, the ODataListBinding automatically adds these paths to $select and $expand — the effect is the same as specifying them in $select on list binding construction. Sorters can also be changed via sort, and the properties to be loaded adapt accordingly.

Example: Dynamic and static sorters

1 <Table growing="true" growingThreshold="5" id="Equipments"
2     items="{
3         path: '/Equipments',
4         parameters: {
5             $$operationMode: 'Server',
6             $orderby: 'Name',
7         },
8         sorter: {
9             path: 'CategoryID',
10            group: true
11            groupPaths: ['Category/CategoryName']
12        }
13    }">

Related Information

API Reference: sap.ui.model.Sorter