Sort
Documents in Payload can be easily sorted by a specific Field. When querying Documents, you can pass the name of any top-level field, and the response will sort the Documents by that field in ascending order. If prefixed with a minus symbol ("-"), they will be sorted in descending order. In Local API multiple fields can be specified by using an array of strings. In REST API multiple fields can be specified by separating fields with comma. The minus symbol can be in front of individual fields.
Because sorting is handled by the database, the field cannot be a Virtual Field. It must be stored in the database to be searchable.
Local API
To sort Documents in the Local API, you can use the sort
option in your query:
To sort by multiple fields, you can use the sort
option with fields in an array:
REST API
To sort in the REST API, you can use the sort
parameter in your query:
To sort by multiple fields, you can use the sort
parameter with fields separated by comma:
GraphQL API
To sort in the GraphQL API, you can use the sort
parameter in your query: