geting iTotalRecords or sEcho or iTotalDisplayRecords from srver side
geting iTotalRecords or sEcho or iTotalDisplayRecords from srver side
Hi, everybody
how can i get in datatables parameters from the topic from server side when they in another json object? I mean something like that
{"content":{"sEcho":1,"iTotalRecords":32,"iTotalDisplayRecords":32,"data":[{"engine":"Gecko","browser":"Firefox 1.0","platform":"2","version":"1.7","grade":"A"},{"engine":"SHasdasdasdmheko","browser":"Firefox 11.5","platform":"11","version":"1.8","grade":"K"},{"engine":"SHmeko","browser":"Firefox 1.5","platform":"2","version":"1.8","grade":"G"}]}}
I try use parameter "sAjaxDataProp": "content.data" but it works only for data array.
Thanks.
how can i get in datatables parameters from the topic from server side when they in another json object? I mean something like that
{"content":{"sEcho":1,"iTotalRecords":32,"iTotalDisplayRecords":32,"data":[{"engine":"Gecko","browser":"Firefox 1.0","platform":"2","version":"1.7","grade":"A"},{"engine":"SHasdasdasdmheko","browser":"Firefox 11.5","platform":"11","version":"1.8","grade":"K"},{"engine":"SHmeko","browser":"Firefox 1.5","platform":"2","version":"1.8","grade":"G"}]}}
I try use parameter "sAjaxDataProp": "content.data" but it works only for data array.
Thanks.
This discussion has been closed.
Replies
[code]
"fnServerData": function( sUrl, aoData, fnCallback ) {
$.ajax( {
"url": sUrl,
"data": aoData,
"success": function(json) {
json = json.content;
fnCallback(json);
},
"dataType": "json",
"cache": false
} );
[/code]
and everything is works for me.
But I'm not sure that's right way.
[code]
"fnServerData": function( sUrl, aoData, fnCallback ) {
$.ajax( {
"url": sUrl,
"data": aoData,
"success": function(json) {
// This piece of code. You can use this value anywhere you like
var iTotalRecs = json['iTotalRecords'];
// load the data
fnCallback(json);
},
"dataType": "json",
"cache": false
} );
[/code]
iTotalRecords and iTotalDisplayRecords are set in the server script based on what is retrieved from your database
sEcho is sent to the server from client and for each draw it will get incremented. You need not set this up.