Datatable using server side got error on pagination and filtered row
Datatable using server side got error on pagination and filtered row
Hi,
I'm working on datatables inside my website in asp.net. With a huge data, I'm using server side with post to call up list base on page. The data show up nicely inside the table but pagination(endless pagination) and total of row(NaN) not show correctly. Here is the dataSrc part that I send back to datatables to restructured the tables accordingly.
},
"dataSrc": function (data) {
var json = $.parseJSON(data.d);
var myData = {};
myData.draw = parseInt(json.draw);
myData.recordsTotal = parseInt(json.recordsTotal);
myData.recordsFiltered = parseInt(json.recordsFiltered);
myData.data = json.searchData;
return myData.data;
}
In the image is the json data I pass back to dataSrc to structured the table list.
Based on the data, I expect the page will be either show only prev and next button or there is only 1 page, but right now there is endless of page display. The total of row will be 10 but I got NaN.
Can anyone help me. Here is the details if you want other code stackoverflow.com/questions/40544765/jquery-datatable-pagination-and-filter-not-display-correctly
This question has an accepted answers - jump to answer
Answers
What is the JSON being returned from the server? I suspect that
data.d
contains a string which you are parsing (line 3). That unfortunately will not work with DataTables and server-side processing.You must have
draw
,recordsTotal
andrecordsFiltered
at the top level of the JSON returned by the server at the moment - DataTables is hard coded that way andajax.dataSrc
cannot override it.You need to change what the server is returning I'm afraid.
Allan