Repopulating a Datatable with new parameters
Repopulating a Datatable with new parameters
I initialised my table like this
[code]
/* POST data to server */
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "xhr.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
} );
} );
[/code]
Later on, I want to update the data in the table. How do I do that?
[code]
/* POST data to server */
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "xhr.php",
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"success": fnCallback
} );
}
} );
} );
[/code]
Later on, I want to update the data in the table. How do I do that?
This discussion has been closed.
Replies
Allan
add params to aoData in fnServerData. this callback is called when you fnDraw while using bServerSide
So now you can do something like this:
[code]
$(document).ready(function() {
$('#example').dataTable( {
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "scripts/server_processing.php",
"fnServerParams": function ( aoData ) {
aoData.push( { "name": "more_data", "value": "my_value" } );
}
} );
} );
[/code]
Allan
I'd like to use this but still have client side sorting and paging.
:)
That new feature is nice. But isn't the solution the same with fnServerData(that is, you try to redefine the function)?
Allan