Include dataTables only once
Include dataTables only once
Description of problem:
I'm including dataTables using webpack from different entrypoints. It happens that on a page, it is included twice at least (on page load and when a modal shows up).
Problem is this code returns valid result only when dataTable is included once in the page:
DataTable().data().toArray() -> This returns { column1: value, column2: value, etc...}
The second time dataTable is included, this same code returns the following:
[ value, value, etc... ]
I'm not sure where dataTables save its instance, but including the js files multiple times in a page, seems to erase data from first initialization.
Is there a workaround to this or a fix I could use ? I've been trying to debug inside datatables.js file and it keep being called everytime it is included.
Answers
DataTables itself won't be including its self on the page twice. It sounds like a bug in whatever build system you are using, or importing different versions. We'd really need a link to a minimal git repo that can reproduce the error to be able to help with this one.
Allan