how to hook response received event of data tables ssp / added item to json encoded array

how to hook response received event of data tables ssp / added item to json encoded array

tashtash Posts: 13Questions: 0Answers: 0
edited September 2012 in General
I added iTotalHours to the server side array. How can I hook this to get that $totalHours record?

[code]
json_encode(array(
'sEcho' => $sEcho,
'iTotalRecords' => $iTotalRecords,
'iTotalDisplayRecords' => $iTotalRecords,
'iTotalHours' => $totalHours,
'aaData' => $aaData
));
[/code]

Replies

  • tashtash Posts: 13Questions: 0Answers: 0
    s/record/value
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    You can either use the 'xhr' event:

    [code]
    $('#myTable').bind('xhr', function ( settings, jqxhr ) {...} );
    [/code]

    Or the fnServerData method .

    Allan
  • tashtash Posts: 13Questions: 0Answers: 0
    Allan, thanks. I'm still a bit unsure of how to actually retrieve something using that. I'm really new to DataTables and I'm not even that experienced with js/jq.

    [code]
    "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
    oSettings.jqXHR = $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": fnCallback
    } );
    console.log( oSettings );
    }
    [/code]

    That console.log logs an object and it looks like what I'm after is inside of jqXHR -> responseText.
    "{"sEcho":"1","iTotalRecords":"20","iTotalDisplayRecords":"20","iTotalHours":"1335.5","aaData":

    As you can see it is the 3rd item in responseText. Can you tell me how I can retrieve 1335.5 in this context?
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    [code]
    "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
    oSettings.jqXHR = $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success":function ( json ) {
    alert( json.iTotalHours );
    fnCallback( json );
    }
    } );
    console.log( oSettings );
    }
    [/code]

    :-)

    Allan
This discussion has been closed.