Accessing the ajax JSON response from within fnDrawCallback

Accessing the ajax JSON response from within fnDrawCallback

ollieollie Posts: 4Questions: 0Answers: 0
edited May 2011 in Plug-ins
The application I am building is specified to include a total value underneath the data table. This total is a total of a column of many more records than will be displayed in the table (hence the decision to use the server-side option).

Ideally I would like to append this value as an additional property in the json returned to the dataTables plugin, eg:

[code]{
sEcho:1,
iTotalRecords:1300,
iTotalDisplayRecords:50,
aaData: [...] ,
iTotal: 4105.25
}[/code]

I hoped to be able to access this value from within fnDrawCallback (or similar callback) to update the displayed total when updating the table itself, but I only appear to have access to the contents of the aaData array.

Would it be possible to write a plugin to expose the raw json response within an appropriate callback without modifying the datatables plugin itself? Ideas welcome!

I’ve been very impressed with the extensibility and extensive documentation of this plugin, thank-you.

I’m currently using:
dataTables 1.7.6

Replies

  • ollieollie Posts: 4Questions: 0Answers: 0
    Solved this today. Was face-palm simple [assuming jQuery 1.5+]

    I remembered that jQuery accepts an array of functions in the success callback of ajax, so was easy as:

    [code]
    'fnServerData' : function(sSource, aoData, fnCallback ){
    $.ajax({
    'dataType': 'json',
    'type': 'GET',
    'url': sSource,
    'data': aoData,
    'success': [fnCallback,fnUpdateTotal]
    });
    }
    [/code]

    Where fnUpdateTotal is my function which receives the full json response as it’s first argument.

    Enjoy!
This discussion has been closed.