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 but without success
$('#example').dataTable( {
"ajax": {
"url": "data.json",
"dataSrc": function ( json ) {
for ( var i=0, ien=json.length ; i<ien ; i++ ) {
json[i][0] = '<a href="/message/'+json[i][0]+'>Next Page</a>';
}
return json;
}
}
} );
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.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.