destroy existing datatables
destroy existing datatables
Hi guys,
Having an issue with reinitializing a datatable object.
Basically I have a div that loads diferent tables (only 1 visible at a time) via ajax.
All tables have the id="datatable" but are completely different (different columns, type of data, etc)
The first load of a table via ajax works fine.
The issue is when a table gets loaded the second time, the paging and sorting doesn´t show. If i give the tables different ids it works fine. But i want to use the same id on the tables.
I'm guessing I have to destroy the previous datatable instances before creating the new.
I'm trying the following, but no joy:
var table = $.fn.dataTable.fnTables();
if ( table.length > 0 ) {
$(table).dataTable().fnDestroy();
}
$('#datatable').dataTable();
Any help would be appreciated.
Thanks!
Having an issue with reinitializing a datatable object.
Basically I have a div that loads diferent tables (only 1 visible at a time) via ajax.
All tables have the id="datatable" but are completely different (different columns, type of data, etc)
The first load of a table via ajax works fine.
The issue is when a table gets loaded the second time, the paging and sorting doesn´t show. If i give the tables different ids it works fine. But i want to use the same id on the tables.
I'm guessing I have to destroy the previous datatable instances before creating the new.
I'm trying the following, but no joy:
var table = $.fn.dataTable.fnTables();
if ( table.length > 0 ) {
$(table).dataTable().fnDestroy();
}
$('#datatable').dataTable();
Any help would be appreciated.
Thanks!
This discussion has been closed.
Replies
var table = $.fn.dataTable.fnTables();
if ( table.length > 0 ) {
$(table).remove();
}
$('#datatable').dataTable();
Allan
Dan