Error on destroy DT with customization
Error on destroy DT with customization
Hello @allan and everyone
I have some issue on destroy a datatable with customization. I created this simple example to explain, and a suggestion to change that line code on destroy function.
Explain:
I change the structure putting another external container on my datatable. When I destroy, I correct remove that container and reorganize my structure as the initial, on the destroy.dt
event.
BUT, the origin
variable is loaded (line 9356) before the trigger is fired (line 9373), so the variable contains the wrong parent and when you use to insertBefore
on line 9419, the error Uncaught DOMException: Node.insertBefore: Child to insert before is not a child of this node
is raised.
Suggestion:
- Load the
origin
variable after firingdestroy.dt
event; - OR use jQuery
insertBefore
instead the native JS funcion at line 9419
That will help everyone who want customize the Datatable structure.
Replies
I think what you might need to do at the moment is use
.destroy(true)
(which will stop DataTables from re-inserting it into the DOM) and a smallsetTimeout
in yourdestroy
event listener: https://jsfiddle.net/a9weo3hq/ .I doubt that is the effect you want though. Did you actually want
table().node()
rather thantable().container()
?Allan
Hello @allan
Thanks the fast reply.
What I expect is that the DataTable has its native behavior when I run
destroy()
. That means, to keep the HTML table after datatable was destroyed.As I insert a new parent to the Datatable, the
origin
variable will have myDIVParent
instantiated. (theorigin
is loaded at the start ofdestroy()
)After, on the
onDestroy
, I rearrange the DOM removing my customDIVParent
. But theorigin
keep the reference to theDIVParent
.After, when in fact, the
origin
is used toinsertBefore
, we have the problem because this variable is no longer "fresh" as the current DOM structure.So my suggestion is to change the base code to just load the origin variable after onDestroy, because it will work because in the
onDestroy
we can rearrange the DOM correctly and the main code will work perfectly.That's my suggestion:
That sounds like a sensible and no hassle change to me - thanks for the suggestion. I've committed it here and it will be in DataTables 1.12.0 when it lands.
Regards,
Allan
@allan
Thank you so much