Ordering and Pagination

Ordering and pagination for results

There are a couple of query options that gives you control over your results and how they are ordered. With them you can not only able to create collection results that are sorted in the required order but to implement paging functionality using the $top and $skip options.


With the $orderby property you are able to sort collection results by one or more properties and forward or reverse direction. You can specify as many fields as you want.

You can use the orderings option to order your results by a certain field. By default it will sort the field from the lowest value to the highest.

The following examples shows how to sort the results by the DisplayName field:


Order by a field in an explicit direction

The following examples shows how to sort the results by the Id field from lowest to highest:

https://dev.demo.sensenet.com/OData.svc/Root/Content/IT/Document_Library?$orderby=Id asc

Order by a field in reverse order

The following example shows how to sort the results by the CreationDate field from closest to earliest:

https://dev.demo.sensenet.com/OData.svc/Root/Content/IT/Document_Library?$orderby=CreationDate desc

Order by a multiple fields

You can specify multiple fields to sort the order of your results by. The results will be ordered first by the first field specified. If any of those values are equal, then those results will be sorted by the next specified field. And so on.

Here is an example that will order the results first by the last modification date of the docs from closest to earliest. It will then sort any docs that have the same ModificationDate by their DisplayName.

https://dev.demo.sensenet.com/OData.svc/Root/Content/IT/Document_Library?$orderby=ModificationDate desc,DisplayName,Name


With the $top option you can limit collection results.



$skip option is for hiding the first given number of elements from the result.



In case of paging the $top option defines the maximum number of documents that the API will return for your query so that the number of docs that will be listed on a page and $skip defines how many docs will be skipped.

Following example demonstrates how to query the second page of a folder list with 3 folders on a page.