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:

aaData: [...] ,
iTotal: 4105.25

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


  • 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:

    'fnServerData' : function(sSource, aoData, fnCallback ){
    'dataType': 'json',
    'type': 'GET',
    'url': sSource,
    'data': aoData,
    'success': [fnCallback,fnUpdateTotal]

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

This discussion has been closed.