Possible to replace underlying data of datatable instead of using 'destroy'?
Possible to replace underlying data of datatable instead of using 'destroy'?
Hi Allan. I have a user list (non-datatable) on the left rail of my web app. When someone selects a user, that users' information is populated on the right.
In one user section I have a DataTable of a user's certifications. Upon first load everything is fine. But when subsequent users users are selected I get the expected 'Cannot reinitialize' error (http://datatables.net/tn/3).
I can get this to work using destroy
, but I do notice a performance hit. I don't want to change the features, just replace the list with new content. Is there a way around this?
This may be not how DataTables is supposed to be used, but thought I'd ask just in case.
Aside from different columns, the code I'm working with is exactly like this reorder example:
https://editor.datatables.net/examples/extensions/rowReorder.html
Thanks,
-Jibran
Replies
When you select a new user you can use
clear
to remove the data from the table and thenrow.add
/rows.add
to add the new rows.Thanks for the response, @rduncecb.
I got your comments working, but once I start interacting with the new data (editing, reordering) I get pretty strange results. Rows start disappearing. It's seem old data is still being expected or referenced.
It might be important to note that when I initialize both the Editor and the DataTable, their AJAX URLs are using the ID of the very first user. This seems problematic. I'm not re-initializing on subsequent calls and not sure how to reset the user_id.
Thoughts?
You've got a mix here, you're supplying
ajax
and also loading data yourself with post. Personally, I would not load rows myself and leave it all up to datatables. Take a look atajax.url
for changing your URL. You could just change the URL, tell the datatable to reload the data and it's all taken care of without usingclear