Destroy and create Datatable

Destroy and create Datatable

lalounelaloune Posts: 16Questions: 3Answers: 0
edited September 2021 in Free community support

Hello

I have to implement the dynamic columns (I have a list of columns as input, and only those have to be rendered)
I read that the only possibility is to destroy the current datatable, and re-create it, so I read the documentation:
https://datatables.net/reference/api/destroy()

and tried it:
https://jsfiddle.net/jzfuobgd/

but it does not seem to work, I get the error:
Query.Deferred exception: e[i] is undefined"

I might have not understand the documentation correctly ?

tia!

Replies

  • kthorngrenkthorngren Posts: 21,352Questions: 26Answers: 4,955
    edited September 2021

    Your test case has this error:

    jquery-3.2.1.min.js:2 Uncaught TypeError: Cannot read properties of undefined (reading 'aDataSort')

    You first Datatable initialization doesn't have a -tag thead` defined. See the HTML requirements doc for more details. I updated your example here to fix the error:
    https://jsfiddle.net/hqapnwue/

    I created a thead with two columns using columns.title. I added a button that runs the destroy() code.

    Kevin

Sign In or Register to comment.