How to write an AJAX in pagination?
How to write an AJAX in pagination?
ashokvedic
Posts: 5Questions: 3Answers: 0
How to write an AJAX in pagination
This discussion has been closed.
Answers
Are you using serverSide? If yes, it's your ajax page that handles all the work. If No, you don't have to do anything, dataTables does it for you. Most people do not need server side processing.
But, if you are using serverside, monitor the HTTP request to your ajax page, you will see variables like draw, start, length. dataTable appends that to the ajax.url that you specified in the setup.
Start is the starting record, length is the number of records to display. dataTables already figured that out for you when the user pressed a page button.
Your SQL or whatever source you are using, then needs to return the records starting at the start value and running for the length number of records.
You then need to return that data in a JSON format. And, return only json data, no html at all.
{ "recordsTotal": # this is the total number of records in your database
, "recordsFiltered": # this is the total number of records that matched the passed filter
, "data" :[ length # of records in JSON format, starting at the start record ]
}
Thank you for reply,
I want to list 10 records of data only, after click of next button again I go to the server and fetch 10 records of data like so.
How can I call server side sql query to get 10 records of data for every click of next button?
Presently its working what you said above
See also the server-side processing manual page and the
serverSide
reference documentation.Allan
There is a pageType of "simple" that seems to provide only a Next and Previous button, seems like that would meet your needs.
https://datatables.net/reference/option/pagingType
You still need to process the URL in the same manner if using serverSide.