Accessing the ajax JSON response from within fnDrawCallback
Accessing the ajax JSON response from within fnDrawCallback
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!
Ive been very impressed with the extensibility and extensive documentation of this plugin, thank-you.
Im currently using:
dataTables 1.7.6
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!
Ive been very impressed with the extensibility and extensive documentation of this plugin, thank-you.
Im currently using:
dataTables 1.7.6
This discussion has been closed.
Replies
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 its first argument.
Enjoy!