destroy() when using language file
destroy() when using language file
hdo
Posts: 3Questions: 1Answers: 0
Calling $("#example").DataTable().destroy();
when a language file is used causes the error
Cannot read property 'parentNode' of null
and the destruction does not work.
A small example is here: http://live.datatables.net/selovibu/1/edit
You can see the detailed error message in the JS-Console of your Browser, and also that the destroy call has no effect (the data-table remains).
This discussion has been closed.
Answers
Hi,
This is actually expected and noted in the
language.url
documentation:Dropping the
destroy
call intoinitComplete
will allow it to work as expected.Allan
Thanks for your answer, i actually didn't notice that section in the docs.
But, it does not solve my problem (I think). In my special case, I need to recreate an existing DataTable, which normally can easily be done with
destroy
. I used the example from your docs and added a language-url: http://live.datatables.net/kojutero/1/editThat fails also with the described error and I can't image how
initComplete
can help in this case.The comment says - some time later. What triggers that? The issue is happening in that code segment because the first FataTable is still initialising. If you moved that code into a button click handler, which might be more realistic, it should work okay.
Allan
I use the datatable with react.js (the combination of both is pretty easy when dealing appropiate with the react lifecycle). Therefore react "decides" when the table should be recreated.
I can work around by setting the different language properties directly... little bit annoying but works.
What really confuses me is that I can use valid options when creating the table (
destroy
andlanguage-url
), and afterwards it is expected that this combination failes with an cryptic error message which does not lead to the problem.But anyway, thanks for your help.
Hi,
This is an example of how it can work: http://live.datatables.net/kojutero/2/edit .
I think it sounds like React is triggering another DataTable create before the old one has finished, which results in the error you are seeing.
I need to look into React integration a bit more!
Allan