Error on destroy DT with customization

Error on destroy DT with customization

rodriformigarodriformiga Posts: 47Questions: 12Answers: 0

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 firing destroy.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

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin

    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 small setTimeout in your destroy event listener: https://jsfiddle.net/a9weo3hq/ .

    I doubt that is the effect you want though. Did you actually want table().node() rather than table().container()?

    Allan

  • rodriformigarodriformiga Posts: 47Questions: 12Answers: 0

    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 my DIVParent instantiated. (the origin is loaded at the start of destroy())

    After, on the onDestroy, I rearrange the DOM removing my custom DIVParent. But the origin keep the reference to the DIVParent.

    After, when in fact, the origin is used to insertBefore, 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:

  • allanallan Posts: 63,540Questions: 1Answers: 10,476 Site admin

    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

  • rodriformigarodriformiga Posts: 47Questions: 12Answers: 0

    @allan

    Thank you so much :)

Sign In or Register to comment.