Re-map iTotalRecords value?

Re-map iTotalRecords value?

DeviationDeviation Posts: 2Questions: 0Answers: 0
edited February 2014 in DataTables 1.9
I'm curious if it's possible to map iTotalRecords to different variable in the JSON response? The web service I call gives the total record count as "event_total" as well as the currently displayed records as "event_count". I searched but couldn't find anything.

If you need sample code, I can provide some. Thanks in advance.

Replies

  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    In DataTables 1.10 you can use `ajax.dataSrc` to provide a function which will perform the mapping: http://next.datatables.net/reference/option/ajax.dataSrc .

    In 1.9- you need to use fnServerData to provide a full Ajax function, with the `success` callback doing the mapping.

    Allan
  • DeviationDeviation Posts: 2Questions: 0Answers: 0
    Forgive me for being a bit ignorant, but how would I do that in my fnServerData function below?
    [code]
    "fnServerData": function( sSource, aoData, fnCallback ) {
    var oSearch = $.ajax({
    type: "POST",
    dataType: 'json',
    url: sSource,
    data: aoData
    })
    .done(function(data) {
    console.log("done");
    fnCallback(data);
    })
    .fail(function() {
    console.log("error");
    });
    }
    [/code]
    "eventList" is my table. I attempted at one point to set the iTotalRecords property in my .done method, but I wasn't sure how to reference the table object.

    Thanks.
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    [code]
    .done(function(data) {
    console.log("done");
    var o = {};
    o.data = data.myData;
    o.draw = data.myDrawCounter;
    // ... etc
    fnCallback(o);
    })
    [/code]

    Allan
This discussion has been closed.