'oSettings.nTable.parentNode is null' when .clone()ing a dataTable

'oSettings.nTable.parentNode is null' when .clone()ing a dataTable

tr333tr333 Posts: 12Questions: 0Answers: 0
edited June 2012 in Bug reports
I'm attempting to un-dataTable a table, to get a straight table element without the dataTable enhancements. I was trying to do this by .clone()ing the dataTable and then running .fnDestroy() on the clone but I'm getting the error 'oSettings.nTable.parentNode is null' whenever I attempt this. If you look at http://live.datatables.net/emeqoz/edit, you will see the error appearing in the browser's JS console.

I'm testing on Firefox with the latest dataTables nightly.

Is there a different method I should be using to get a "clean" copy/clone of the table?

Replies

  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Destroying an non-DataTable table would result in an error since DataTables would be trying to act on a table that doesn't have the 'enhancements' that DataTables adds. I suspect what you will need to do is use fnGetData to get the data source for the table and then loop over that constructing your new table. The other option would be to clone the table, thead and tbody nodes as shallow clones (you'd need to use DOM methods directly for that since jQuery doesn't have a shallow clone option), and then use fnGetNodes to get the array of TR elements which you can deep clone and append to your cloned tbody.

    Allan
  • tr333tr333 Posts: 12Questions: 0Answers: 0
    Thanks Allan. I would have thought that doing "clone.dataTable()" would add in the DataTables 'enhancements' to the table in JS before running fnDestroy() on it, but maybe not. I'll give your suggestion a try on manually constructing the table nodes.
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    It doesn't work like that because DataTables has a reference to the table node (that is its "grounding point") but the cloned elements is not the original - thus the match doesn't work and it explodes :-).

    Ultimately it might be nice to have a 'clone' API plug-in method for DataTables in future. Added to the to-do list :-)

    Allan
This discussion has been closed.