sAjaxDataProp and top level variables

sAjaxDataProp and top level variables

jdkingjdking Posts: 4Questions: 1Answers: 0
edited April 2014 in Bug reports
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?

Replies

  • allanallan Posts: 61,649Questions: 1Answers: 10,093 Site admin
    There isn't an option to tell DataTables where to get the sEcho etc variables - they are hardcoded in the core.

    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
  • jdkingjdking Posts: 4Questions: 1Answers: 0
    Thanks!

    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?
  • allanallan Posts: 61,649Questions: 1Answers: 10,093 Site admin
    Not that I can see.

    Allan
This discussion has been closed.