sAjaxDataProp and top level variables
sAjaxDataProp and top level variables
jdking
Posts: 4Questions: 1Answers: 0
I'm trying to push all ajax responses through a container array so I can integrate with our existing error display code, but I'm having trouble with top-level variables DataTables expects (such as sEcho and iTotalRecords).
So for example I have something like:
$ajax_array['container']['notifications'] = array(list of errors occurred here)
$ajax_array['container']['results'] = array(data table requested data);
echo json_encode($ajax_array['container']);
I can setup the data table by using sAjaxDataProp: "results.aaData", but I don't know what to do about the top level variables. Is there some easy way to tell the datatable where to find these variables?
So for example I have something like:
$ajax_array['container']['notifications'] = array(list of errors occurred here)
$ajax_array['container']['results'] = array(data table requested data);
echo json_encode($ajax_array['container']);
I can setup the data table by using sAjaxDataProp: "results.aaData", but I don't know what to do about the top level variables. Is there some easy way to tell the datatable where to find these variables?
This discussion has been closed.
Replies
There are two options:
1. Modify DataTables
2. Provide an fnServerData function which will get the data from the server and then return it in the format needed by DataTables.
Allan
I did this:
"fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
oSettings.jqXHR = $.getJSON(sSource,
aoData,
function(data){
var dataTableResults = data.results;
fnCallback(dataTableResults);
});
},
...and it seems to be working fine. Did I miss anything in how I configured this that will cause me problems later?
Allan