Delete Data Tables from DOM

Delete Data Tables from DOM

hemmeterhemmeter Posts: 6Questions: 0Answers: 0
edited November 2010 in General
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!

Replies

  • hemmeterhemmeter Posts: 6Questions: 0Answers: 0
    edited November 2010
    I had some bigger questions, so I asked this and more in another thread (http://datatables.net/forums/comments.php?DiscussionID=3247). I believe the answer to this question is...

    [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]
This discussion has been closed.