Displaying custom data from the same GET request as Datatables
Displaying custom data from the same GET request as Datatables
I have modified my server side code to output A users avatar as well as the table data like so:-
[code]
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array(),
"avatar" => bp_core_fetch_avatar( array('item_id' => $uid, 'type' => 'thumb') )
);
[/code]
This now produces all the data I want put into datatbles and returns in the JSON also.
Works great, but I would like to be able to map this data into an element.
Currently I am using a second PHP file, custom written by myself to return this and it works perfectly but I see no point in having two server hits when I can easily pass this data from within the same GET request as the table information.
How can I retrieve this HTML?
[code]
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array(),
"avatar" => bp_core_fetch_avatar( array('item_id' => $uid, 'type' => 'thumb') )
);
[/code]
This now produces all the data I want put into datatbles and returns in the JSON also.
Works great, but I would like to be able to map this data into an element.
Currently I am using a second PHP file, custom written by myself to return this and it works perfectly but I see no point in having two server hits when I can easily pass this data from within the same GET request as the table information.
How can I retrieve this HTML?
This discussion has been closed.
Replies
[code]
$(document).ready(function() {
$('#example').dataTable( {
"sAjaxSource": "data_source.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"url": sSource,
"data": aoData,
"success": function(data, textStatus, jqXHR) {
// find avatar attached to your "data"
console.log(data.avatar);
fnCallback(data, textStatus, jqXHR);
}
} );
}
} );
} );
[/code]
see http://www.datatables.net/ref#fnServerData
and http://api.jquery.com/jQuery.ajax/