arvinsim arvinsim - 23 days ago 8
jQuery Question

Repopulating a Datatable with new parameters

I initialised my table like this

/* 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
} );
}
} );
} );


Later on, I want to update the data in the table. How do I do that?

Answer

I had the exact same problem, and ended up solving it like this:

function GetDatatable(parameter) {
    $('#example').dataTable().fnDestroy();
    $('#example').dataTable({
...

Then you can add your new parameters in aoData after that. It's an ugly hack, but it works.

Comments