TypeError: headerCells[i] is undefined (when re-creating table)
TypeError: headerCells[i] is undefined (when re-creating table)
Hi, I am trying to use datatable to display some results from a model. The results are picked up by ajax and I am building an array of objects with the data I need to display. The user selects variables from a diagram which causes columns to be added to the table.
The first time the table is displayed, all is well. (it only has one row initially). Then I add a second variable and re-create it (as the only way to add a column). ...but now the table only has the first heading, and the navigation options are not displayed.
The JS console includes the error in the subject line, jquery.dataTables.js line 3965
I have put together an illustration of the problem at jsfiddle.net/mj88y/ -- the first call to datatable is commented out, to show that the data displays correctly if there is only one call. If you uncomment the first call and run it again, the problem will occur.
Any ideas what is going on?
Answers
Got the answer from this thread:
http://datatables.net/forums/discussion/5287/destroy-and-recreate-troubles
You have to destroy it explicitly then call empty()
I'm new to DataTables and haven't got a feel for how bug-riddled it is yet!