Is this a bug in "destroy" option?

Is this a bug in "destroy" option?

daviddehdaviddeh Posts: 2Questions: 1Answers: 0

Hi everyone,

I have a simple JSFiddle to demonstrate the problem.

https://jsfiddle.net/ddehghan/j26d2pdx/2/

If i switch the data of DataTables between 2 different datasets I run into a script error. Am I doing something wrong?

Any help would be appreciated.

Thanks
David

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,695Questions: 1Answers: 10,500 Site admin
    Answer ✓

    So the issue here is that the tables are being constructed with a different number of columns. When you use destroy is leaves the table in the DOM, so if you click data 1 first you have a table with 3 columns - then load data 2, the configuration only has two columns but the HTML has three. Hence the issue.

    The answer is to use the destroy() method and $().empty(): https://jsfiddle.net/j26d2pdx/7/

    Allan

  • daviddehdaviddeh Posts: 2Questions: 1Answers: 0

    Thanks you so much. that works very well. :-)

This discussion has been closed.