How do I reload DataTables with new JSON data?
How do I reload DataTables with new JSON data?
Great plugin!
I guess the question is self explanatory.
I've created a reporting module - when a user clicks on a report, it renders the DataTable. So each time a user chooses a different report, DataTable will be rendered with fresh JSON data from the server (fresh aoColumns and aaData).
I'm having troubles achieving the RELOAD. It works first time but I don't know how to reload it with fresh data or essentially re-initialize the table.
Code below is how I load the data. Is there a way I can use the API to reload only the aoColumns and aoData but leave the rest of my settings intact ?
[code]
function getReport(reportId) {
$.post('/Services/Reporting.asmx/GetReport', { reportId: reportId }, function (response) {
var json = $.parseJSON(response.text);
setupTableFooter(json);
//oTable.fnReloadAjax(json);
otable = null;
var settings = {
"bJQueryUI": true,
"bProcessing": true,
"bRetrieve": true,
"sDom": '<"top"T<"clear">Rfrti<"clear">p<"clear">>',
"oTableTools": {
"sSwfPath": "/Scripts/datatables/media/swf/copy_cvs_xls_pdf.swf",
"sRowSelect": "single"
},
"sPaginationType": "full_numbers",
"bScrollCollapse": true,
"bScrollAutoCss": false,
"oColVis": {
"buttonText": " ",
"bRestore": true,
"sAlign": "left"
},
"oLanguage": { "sSearch": "Search all columns:" },
"aaData": json.aaData,
"aoColumns": json.aoColumns
}
oTable = $("#datatable").dataTable(settings);
});
}
[/code]
I guess the question is self explanatory.
I've created a reporting module - when a user clicks on a report, it renders the DataTable. So each time a user chooses a different report, DataTable will be rendered with fresh JSON data from the server (fresh aoColumns and aaData).
I'm having troubles achieving the RELOAD. It works first time but I don't know how to reload it with fresh data or essentially re-initialize the table.
Code below is how I load the data. Is there a way I can use the API to reload only the aoColumns and aoData but leave the rest of my settings intact ?
[code]
function getReport(reportId) {
$.post('/Services/Reporting.asmx/GetReport', { reportId: reportId }, function (response) {
var json = $.parseJSON(response.text);
setupTableFooter(json);
//oTable.fnReloadAjax(json);
otable = null;
var settings = {
"bJQueryUI": true,
"bProcessing": true,
"bRetrieve": true,
"sDom": '<"top"T<"clear">Rfrti<"clear">p<"clear">>',
"oTableTools": {
"sSwfPath": "/Scripts/datatables/media/swf/copy_cvs_xls_pdf.swf",
"sRowSelect": "single"
},
"sPaginationType": "full_numbers",
"bScrollCollapse": true,
"bScrollAutoCss": false,
"oColVis": {
"buttonText": " ",
"bRestore": true,
"sAlign": "left"
},
"oLanguage": { "sSearch": "Search all columns:" },
"aaData": json.aaData,
"aoColumns": json.aoColumns
}
oTable = $("#datatable").dataTable(settings);
});
}
[/code]
This discussion has been closed.
Replies
1. Destroy the table and initialise it again
2. Call the API method fnClearTable and then fnAddData to add you new data (I'd say this one is preferable).
Allan