Ajax json request with limit and skip because of large data
Ajax json request with limit and skip because of large data
Hello friends,
I am relatively new to datatables api. But I really love it.
My datatable is requesting json with ajax. The problem I have is, that it would take way too long to load whole json from my server.
On server-side, I implemented 'limit' and 'skip' query parameter to limit the json response.
Is there a way to adapt this to datatables?
My default ajax url in datatables is '[domain]/testjson/trackings.json'.
For example, user has selected to show 10 entries per page and is on the first page, then ajax request url should be '[domain]/testjson/trackings.json?limit=10&skip=0' instead of my default url.
If the user goes to the second page, then ajax should be '[domain]/testjson/trackings.json?limit=10&skip=10' to load the second 10 results from server.
Is there a build-in function to solve this? Or how should I handle this?
Please let me know if I should phrase my question differently or if it is clear to understand.
Thank you in advance!
Best regards,
Matteo
This question has an accepted answers - jump to answer
Answers
Datatables uses Server Side Processing for server side paging. See the Server side processing protocol for details. Datatables provides some server side libraries. See this blog for their usage.
Kevin
Hello @kthorngren
Thanks a lot for your quick response which seems to answer my question.
It would be helpful if you could confirm if I understood correctly the following:
I need to add the following code to my Datatable:
Is that correct?
Thank you and best regards,
Matteo
That sounds correct. Did you try it?
Kevin
@kthorngren if this works it would be awesome!!
I will try soon and update.
Thanks again!
Matteo
Just make sure your server script returns the expected response data so datatables knows the number of records, etc.
Kevin
@kthorngren thank you for the hint, I will make sure to adjust the response accordingly.
Matteo