Can't reference existing datatable

Can't reference existing datatable

parsonsparsonsparsonsparsons 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.

Answers

  • parsonsparsonsparsonsparsons Posts: 29Questions: 8Answers: 0

    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.

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769
    edited November 2019

    Sounds like you are using ajax and attempting to use var 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 use initComplete.

    Kevin

This discussion has been closed.