Pagination & Sorting
Use sorting and pagination if your response is valid JSON.
We recommend using render cache so that the results of pagination and sorting are visible.
We will see the work using the example below.
Pagination
Working with pagination is as simple as possible, but for it to work, you must use sorting.
In total, the required set of GET parameters is presented below.
limit (number of records in response)
page
sortByAsc or sortByDesc (sort in ascending or descending order)
Sorting
Use one of the two GET parameters to sort below.
sortByAsc (sort in ascending)
sortByDesc (descending order)
Exmaples
At the beginning of the article there is a link to a live example. Below are a few responses from it for quick reference.
// ?page=1&limit=2&sortByDesc=id
{
"errors": null,
"responseData": [
{
"id": "10",
"email": "[email protected]",
"createdAt": "1472971147",
"content": "sometext"
},
{
"id": "9",
"email": "[email protected]",
"createdAt": "527244709",
"content": "sometext"
}
]
}
// ?page=2&limit=2&sortByDesc=id
{
"errors": null,
"responseData": [
{
"id": "8",
"email": "[email protected]",
"createdAt": "1275109461",
"content": "somecontent"
},
{
"id": "7",
"email": "[email protected]",
"createdAt": "931692331",
"content": "somecontent"
}
]
}
// ?page=1&limit=2&sortByAsc=id
{
"errors": null,
"responseData": [
{
"id": "1",
"email": "[email protected]",
"createdAt": "822285684",
"content": "somecontent"
},
{
"id": "2",
"email": "[email protected]",
"createdAt": "683679219",
"content": "somecontent"
}
]
}
// ?page=2&limit=2&sortByAsc=id
{
"errors": null,
"responseData": [
{
"id": "3",
"email": "[email protected]",
"createdAt": "1379197938",
"content": "somecontent"
},
{
"id": "4",
"email": "[email protected]",
"createdAt": "630925663",
"content": "somecontent"
}
]
}
Last updated