Can't reference existing datatable
Can't reference existing datatable
parsonsparsons
Posts: 29Questions: 8Answers: 0
I am trying to reference an existing datatable I have already created by doing the following:
var table = $('#mytable').DataTable();
I get this error when attempting to do this:
Cannot read property 'aDataSort' of undefined
Cannot read property 'parentNode' of null
Any idea why this is happening? Thanks.
This discussion has been closed.
Answers
From testing it looks like i was trying to call:
var table = $('#mytable').DataTable();
Before the datatable was completely initialized. If I add a different button and click that with this code it does not break.
Sounds like you are using
ajax
and attempting to usevar table = $('#mytable').DataTable();
before the ajax response and Datatables has completed initialization. Ajax is an async operation. If you need to do something directly after Datatables initializes you can useinitComplete
.Kevin