How to reload the selected tab? Actually I have problem with reloading part. When I add my data I\'ll successfully saved in datatable but in id field in database it shows pr
Simpler solution:
var dt = $('#table_scroll').dataTable();
$.getJSON(url, null, function (json) {
dt.fnClearTable();
dt.fnAddData(json.aaData);
dt.fnDraw();
});
None of these solutions worked for me, but I did do something similar to Masood's answer. Here it is for posterity. This assumes you have <table id="mytable"></table>
in your page somewhere:
function generate_support_user_table() {
$('#mytable').hide();
$('#mytable').dataTable({
...
"bDestroy": true,
"fnInitComplete": function () { $('#support_user_table').show(); },
...
});
}
The important parts are:
bDestroy
, which wipes out the current table before loading.hide()
call and fnInitComplete
, which ensures that the table only appears after everything is loaded. Otherwise it resizes and looks weird while loading.Just add the function call to $(document).ready()
and you should be all set. It will load the table initially, as well as reload later on a button click or whatever.
To reload the table data from Ajax data source, use the following function:
dataTable.ajax.reload()
Where dataTable
is the variable used to create the table.
var dataTable = $('#your_table_id').DataTable({
ajax: "URL"
});
See ajax.reload() for more information.
You could use this function:
function RefreshTable(tableId, urlData)
{
//Retrieve the new data with $.getJSON. You could use it ajax too
$.getJSON(urlData, null, function( json )
{
table = $(tableId).dataTable();
oSettings = table.fnSettings();
table.fnClearTable(this);
for (var i=0; i<json.aaData.length; i++)
{
table.oApi._fnAddData(oSettings, json.aaData[i]);
}
oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
table.fnDraw();
});
}
Dont' forget to call it after your delete function has succeded.
Source: http://www.meadow.se/wordpress/?p=536