Pagination doesnot work
Pagination doesnot work
Hi,
Im using datatable-1.10.12 with .net webservice as backend service. data table is getting records from the server . but datatable pagination shows this "Showing 0 to 0 of 0 entries (filtered from NaN total entries)". Later i found out that there is 'd' prefix in returned json so i included dataSrc to filter that json. but it still shows the same message, what to do?
"processing": true,
"serverSide": true,
"ajax": {
type: "POST",
url: "../WebServices/dDataTable.asmx/GetAllTableData",
dataType: 'json',
contentType: "application/json; charset=utf-8",
data: function (d) {
return "{'Kobj':" + JSON.stringify(d) + "}";
},
dataSrc: function (jsn) {
jsn = JSON.parse(jsn.d);
debugger;
return jsn.data;
}
},
this is my returned json from server after filtered by dataSrc
"{"draw": 1,"recordsTotal": 10,"recordsFiltered": 10,"data": [["cb","ero","son","Test","product","ja","8.9"]]}"
when i put debugger in dattable.js _fnAjaxDataSrc( settings, json ), here json is not from datasrc so it include 'd' prefix
so below variables getting undefined value
var draw = compat( 'sEcho', 'draw' );
var recordsTotal = compat( 'iTotalRecords', 'recordsTotal' );
var recordsFiltered = compat( 'iTotalDisplayRecords', 'recordsFiltered' );
i want server side processing and how do i get 'd' trimed json to this fnAjaxDataSrc( settings, json ).
is dataSrc is sufficient?
Answers
Unfortunately
ajax.dataSrcdoesn't work with server-side processing quite like you are expecting. That function must return the array of data, but that means there there is currently no way forajax.dataSrcto work withdraw,recordsTotal, etc. They must be in the top level of the JSON for server-side processing to work atm.The only other option is to use the
xhrevent to modify the JSON returned from the server.Allan
Can you create a new object in this function and return that as the correctly formatted array?
Not for the server-side processing parameters I'm afraid. Yes, it can return a new array that contains the row information, but the information for the server-side processing parameters must be read from the original JSON (that JSON can be modified in
ajax.dataSrc).That is a limitation that I am aware of and will address in a future version.
Allan