Server Side pagination using Data table
Server Side pagination using Data table
How can I achieve server side pagination using data table? Currently, on load of page I am initializing the data table & filling the table with Data (JSON) coming from database via Java servlet controller. I am making an Ajax call by passing search criteria in query string. Since we have lakhs of records, we have planned for server side pagination to improve performance.
For this the backend service developer has given me a service that gives me the per page records but takes inputs like PAGE NUMBER, NO OF PAGE RECORDS, SORT ORDER, SORT COLUMN.
I have to override data table implementation to pass these to service via Ajax request query string. I don't know if there is a way to achieve this. Please suggest!!!
This question has accepted answers - jump to:
Answers
I followed the example to test server side pagination, but it is not showing up the data in my table. Anything wrong?
Here is my JSON data:
{"masterObject":{"draw":1,"myData":[{"code":"code1","description":"Desc1"},{"code":"code2","description":"Desc2"},{"code":"code3","description":"Desc3"},{"code":"code4","description":"Desc4"},{"code":"code5","description":"Desc5"},{"code":"code6","description":"Desc6"}],"recordsFiltered":74,"recordsTotal":210},"OUTPUT_STATUS":1}
It doesn't appear to follow the requirements of server-side processing. There is no option to have the server-side information nested in another object.
If you require that, you will need to use
ajax
as a function and make a custom call to the server.Allan
My JSON data was not in the reequired format as pointed by you. Also columns option was errorneous. Here is the changes that are working:
And here is the JSON data:
{"data":[{"code":"code11","description":"Desc11"},{"code":"code21","description":"Desc21"},{"code":"code31","description":"Desc31"},{"code":"code41","description":"Desc41"},{"code":"code51","description":"Desc51"},{"code":"code61","description":"Desc61"},{"code":"code71","description":"Desc71"},{"code":"code81","description":"Desc81"}],"draw":"1","recordsFiltered":134,"recordsTotal":134}
How can I get data of one column into another column?. In below columnDefs option, I am not getting the second column value with full[1]. Instead it is showing as 'undefined'.
full[1]
is trying to access an array, but you are giving it objects. So you would usefull.description
(for example).Allan
And its working :)
Thanks Allan!
Allan,
Although I got the above sample working, I am facing difficulty in converting it to the client-side paging like pattern. Following are the code listings of my current client side paging data table which is perfectly working:
Table Init
Ajax Call (OnLoad after table initializaion/ Search record/Adding new record/ deleting a record)
Input to fnAddData() function
Now in my server side paging code, ajax is bound in table initialization itself. How can I separate it to make it look similar to my above client paging program. Basically I need to:
Please advise as I am trying things without success :(
Can you link to the page so I can attempt to debug it please.
Allan
Allan,
I got it. I actually I had to do:
while this is working, load version of that is not working. Actually when I use the following line, the table is freezing with "Processing..." message. URL is fine & no error in developer tool console. What could be the issue:
myTable with server side = "true" is initilaised in earlier listings.