Ability to override _fnAjaxUpdateDraw?

Ability to override _fnAjaxUpdateDraw?

lastbytelastbyte Posts: 8Questions: 0Answers: 0
edited April 2014 in DataTables 1.10
I'm using server side data, but .net likes to return the data under the "d" property (ie, {d: {recordsTotal: 30, data: [...]}}). I see that I can use the 'dataSrc' property to specify how to get the data, but is there something similar for the other properties (recordsTotal, recordsFiltered, draw)?

I see that really nice _fnAjaxUpdateDraw function in the code. Is there any way that I can override it?

Replies

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    You can use `dataSrc` as a function and remap the return from .NET into the object format DataTables expects: http://next.datatables.net/reference/option/ajax.dataSrc

    Allan
  • lastbytelastbyte Posts: 8Questions: 0Answers: 0
    I tried using that, but it seems to only allow one to remap the 'data' parameter (not the recordsTotal, draw, and recordsFilter params). The code seems to confirm my suspicions (in function _fnAjaxUpdateDraw). Am I doing something wrong?
  • lastbytelastbyte Posts: 8Questions: 0Answers: 0
    For anybody who's run into this issue, I found an easy work-around using a converter function:

    [code]
    var tableOpts = {
    ajax: {
    url: 'Blah.aspx/GetData',
    data: function (d) {
    return $.toJSON({
    id: 3,
    draw: d.draw,
    order: d.order
    });
    },
    converters: {
    "json net": function(msg) {
    return msg.hasOwnProperty('d') ? msg.d : msg;
    }
    },
    type: 'POST',
    contentType: 'application/json; charset=utf-8',
    dataType: 'json net'
    },
    serverSide: true,
    processing: true
    };

    var table = $('#report').dataTable(tableOpts)
    [/code]
This discussion has been closed.