Sorry for this basic question.. but I can't figure out by myself how to apply the explanations given on this site about Ajax to my Datatable.
I have a text box near my Datatable. It has CSS Class "num_items". When I type a value in it makes another Ajax call and redraws the Datatable based on a query result from the database and server side processing:
$("input[type='text'].num_items").focusout( function() {
oTable.fnDraw();
} );
I use Datatables "fnServerData": parameter within the var oTable = $("#mydatatable").dataTable( {.....}); call to send the value in the text box to server side processing to ultimately query the database...
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "name": "min_qty", "value": $("#minQty").val() } );
aoData.push( { "name": "max_qty", "value": $("#maxQty").val() } );
$.ajax( {
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
But now I want to do something a bit different. I have a PopUp overlay that I want to display values in based on the row in the datatable that the user clicks on. I want to query the database to get this additional info and will need to send a unique identifier from the row that was clicked on. So basically I need to do an Ajax call but I don't know how to!
Can I do something like this? When the row is clicked on I want to make a query to the database but without having to use oTable.fnDraw(); which would make a full resort and re-filter of the table.
$(document).on("click","table.display td.drug_name", function() {
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData.push( { "name": "min_qty", "value": $("#minQty").val() } );
aoData.push( { "name": "max_qty", "value": $("#maxQty").val() } );
$.ajax( {
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
$('#my_popup').popup('show');
});
Finally, with serverside processing I'm used to having the line:
echo json_encode( $output );
.. which someone magically returns the query result from the database and Datatables knows how to display that in the table. But in my case here, how would I capture the query result in my jQuery onclick Row function..
$(document).on("click","table.display td.drug_name", function() {
..
Want to make Ajax call here and get result back here also !!
..
});
Sorry for the long winded question!
Thank you in advance.