Delete Data Tables from DOM
Delete Data Tables from DOM
Hi,
First off, thanks for the fantastic plugin! It's making my life easier and I am looking forward to deploying it out to my users!
My app allows a user to run queries and the results are displayed in dynamic tables enhanced by Data Tables. Until they query, I don't know what the table will be like, so I create a table from scratch in JavaScript and use the JavaScript Array to build it. Users can opt to append new queries to the results or eliminate current results and start fresh.
My question is the proper way to wipe the page clean of a Data Tables enhanced table. I want to be sure and remove the JavaScript objects from memory too so the page isn't hanging onto anything. I put all my tables in a DIV. Is it as simple as just saying...
[code]
jQuery('#dataTables').html('');
[/code]
That will clear the DIV of all HTML inside it, but I want to be sure I've cleaned out any data tables objects behind the scenes. Sometimes a table I clean out will have ~500 rows in it and I'd rather not have that hanging around in memory.
Thanks!
First off, thanks for the fantastic plugin! It's making my life easier and I am looking forward to deploying it out to my users!
My app allows a user to run queries and the results are displayed in dynamic tables enhanced by Data Tables. Until they query, I don't know what the table will be like, so I create a table from scratch in JavaScript and use the JavaScript Array to build it. Users can opt to append new queries to the results or eliminate current results and start fresh.
My question is the proper way to wipe the page clean of a Data Tables enhanced table. I want to be sure and remove the JavaScript objects from memory too so the page isn't hanging onto anything. I put all my tables in a DIV. Is it as simple as just saying...
[code]
jQuery('#dataTables').html('');
[/code]
That will clear the DIV of all HTML inside it, but I want to be sure I've cleaned out any data tables objects behind the scenes. Sometimes a table I clean out will have ~500 rows in it and I'd rather not have that hanging around in memory.
Thanks!
This discussion has been closed.
Replies
[code]
// Destroy each datatable in the div
var allTables = jQuery('#allDataTables table.display');
for(var i = 0; i < allTables.length; i++) {
jQuery('#' + allTables[i].id).dataTable().fnDestroy();
}
// Clear the DIVs html
jQuery('#allDataTables').html('');
[/code]