destroy does not destroy all table information

destroy does not destroy all table information

chrhanchrhan Posts: 2Questions: 1Answers: 0

I am Trying to reuse a table by setting destroy:true option
But if the first table had 10 columns and the new table contains just 4 columns, it seems that the 6 previous headers hangs over,causing javascript error in jquery.datatables.js line 1154 - Typeerror: col is undefined.
if line 1154 if modified to:
if (col && col.mData ===i ) {
the table will run with the 4 new headers - but then additional old 6 columns headers will show
How do I really destroy ALL information for the dataTable making the table free for use next time ?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,374Questions: 26Answers: 4,957
    Answer ✓

    Maybe the destroy() API would be better to use as Datatables doesn't remove the columns so you will need to use something like jQuery empty(). See the examples in the destroy() docs.

    Kevin

  • rf1234rf1234 Posts: 3,004Questions: 87Answers: 421

    It is also important to know that event handlers are not automatically deleted if you destroy a data table. I only use "destroy()" with Editor but that is the same thing.

    This is typical code also killing the event handlers:

    if ( ! $.isEmptyObject(editor) ) {
        editor.off('open postSubmit submitSuccess initCreate ');
        editor.destroy();
    }
    
  • chrhanchrhan Posts: 2Questions: 1Answers: 0

    Thank you kthorngren - the .empty() function did the trick

Sign In or Register to comment.