I'm using datatables and using bootstrap-daterangepicker to select a range for which data will be shown in Datatables.
It is working fine.
The problem is when I select a new range in daterangepicker, it provides me with a callback function where I can do my stuff. In that callback function, I'm calling Datatables again. But since the table is already being created, how can I destroy the previous table and show a new one in it's place?
Kindly help. I'm stuck. :(
EDIT: I've the following code:
$(element).daterangepicker({options},
function (startDate, endDate) { //This is the callback function that will get called each time
$('#feedback-datatable').dataTable({
"sDom": "<'row-fluid'<'span6'l><'span6'f>r>t<'row-fluid'<'span6'i><'span6'p>>",
"sPaginationType": "bootstrap",
"oLanguage": {
"sLengthMenu": "_MENU_ records per page",
"oPaginate": {
"sPrevious": "Prev",
"sNext": "Next"
}
},
"aoColumnDefs": [{
'bSortable': false,
'aTargets': [2,4]
}],
"bAutoWidth": false,
"aoColumns": [
{"sWidth": "20%"},
{"sWidth": "15%"},
{"sWidth": "45%"},
{"sWidth": "15%"},
{"sWidth": "5%"}
]
});
}
For the google searchers
Very hardly I managed to destroy the
Datatable
, Empty it's all previous data before loading new data and re-initializing Datatable by doing like this,Just add this parameter to your declaration:
Then whenever you want to "recreate" the table it won't drop an error
P.S. You can create a function to get the required parameters and then reinitialize the table with different options at runtime.
For example I use this one in my programs, if it helps you can adapt it to your needs
Ivan.
For DataTables 1.10, the calls are:
From DataTable
Reload a full table description from the server, including columns:
Hope it will help
this should destroy dataTable, then you will have to reinitialize dataTable.
On DataTables 1.10 and above you can use
"destroy": true
Read more details here