Re-rendering table from pre-existing column info
Re-rendering table from pre-existing column info
Hello, I am working on adding columns to a table (reloading the table with updated data) and I have it working with the original aoColumns array but instead I would like to pull the table's existing aoColumns settings using something like fnSettings().aoColumns. That way I could pull the current columns in case they have been updated and keep any settings like the current sorting or whatever. If I pass fnSettings().aoColumns to the new datatable as it is it works but if I try to add a new column with just stitle and mdata to that array it doesn't. I've even tried copying one of the existing columns data and changing the title/mdata but that doesn't work either. Is there a better way to do this or is there a required set of options I need to include with a new column since the others have more data from initialization? Thanks!
This discussion has been closed.
Replies
[code]
Uncaught TypeError: Cannot read property 'className' of undefined jquery.dataTables.js:4274
_fnSortingClasses jquery.dataTables.js:4274
fnDestroy jquery.dataTables.js:5211
[/code]
At least there is a workaround to manually delete and reinit the table and dom node, maybe I'm not understanding the best approach here to pull and refresh the data from an existing table.
colData = example3.fnSettings().aoColumns
colData.push({
sTitle: "newcol",
mData: "newcol"
})
[/code]
I'm not surprised that's throwing an error - you are manipulating a private variable by adding new (incomplete) data to the private `aoColumns` parameter in the settings object. DataTables will see that there are then three entries for that column, attempt to work on three columns, find there are only two and go boom.
I'd very strongly suggest you don't manipulate the settings object properties at all - that's what the API is there for. Treat the options from fnSettings as read only.
Allan