geting iTotalRecords or sEcho or iTotalDisplayRecords from srver side

geting iTotalRecords or sEcho or iTotalDisplayRecords from srver side

pavelpavel Posts: 2Questions: 0Answers: 0
edited November 2012 in General
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.

Replies

  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    data.iTotalRecords is what you have to use on successful ajax call. Same goes for sEcho and iTotalDisplayRecords
  • pavelpavel Posts: 2Questions: 0Answers: 0
    edited November 2012
    Thanks for answer, girishmr, but I'm a little confused. Did You mean content.iTotalRecords for my example? And how I can set this parameter on successful ajax call? Now i fix this with this code:
    [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.
  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    Your code can be

    [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.
This discussion has been closed.