i have a get api with serverside pagination,
http://demo.example.com?offset=0&limit=10
How do i implement in Datatables. I tried below
Finally got some time to implement a sample for server side pagination.
Below is the complete example for it. Note the input that we are giving to API call. you can take a look at this ajax: function ( data, callback, settings )
which is the main key and from where we are getting proper pagenumber and pagesize.
Jquery Datatable Example
First name
Last name
Position
Office
Start date
Salary
In the above example, we are integrating with an api which returns me a JSON of below format.
In the below format note the properties "TotalRecords", "RecordsFiltered". These are needed for datatable to recalculate pagination stuff and display proper number of pages.
{
"Data":[
{
"first_name":"FirstName 5",
"last_name":"LastName 5",
"position":null,
"office":"start date 5",
"start_date":"office 5",
"salary":50
},
{
"first_name":"FirstName 6",
"last_name":"LastName 6",
"position":null,
"office":"start date 6",
"start_date":"office 6",
"salary":60
},
{
"first_name":"FirstName 7",
"last_name":"LastName 7",
"position":null,
"office":"start date 7",
"start_date":"office 7",
"salary":70
},
{
"first_name":"FirstName 8",
"last_name":"LastName 8",
"position":null,
"office":"start date 8",
"start_date":"office 8",
"salary":80
},
{
"first_name":"FirstName 9",
"last_name":"LastName 9",
"position":null,
"office":"start date 9",
"start_date":"office 9",
"salary":90
}
],
"TotalRecords":100,
"RecordsFiltered":100
}