Best Practices for Efficient DataTable Reuse in Ajax Page
Best Practices for Efficient DataTable Reuse in Ajax Page
Hello:
I have a pure Ajax application where I load tabular data into a single DataTables instance. The page provides ways to load new data. After each data load, I'd like to reuse the same DataTables instance.
Is the best practice for making this DataTables instance more efficiently reused simply to set "bDestroy" to true?
I am finding that when I do this, the inner table of rows gets narrower (by perhaps 5px each time) each successive reload.
Is it better to blow the entire table away each time (replacing the DOM node with a new empty table)?
Note that there is no prior HTML table that needs to be restored, so this step doesn't even need to be done.
Thanks,
Glenn
I have a pure Ajax application where I load tabular data into a single DataTables instance. The page provides ways to load new data. After each data load, I'd like to reuse the same DataTables instance.
Is the best practice for making this DataTables instance more efficiently reused simply to set "bDestroy" to true?
I am finding that when I do this, the inner table of rows gets narrower (by perhaps 5px each time) each successive reload.
Is it better to blow the entire table away each time (replacing the DOM node with a new empty table)?
Note that there is no prior HTML table that needs to be restored, so this step doesn't even need to be done.
Thanks,
Glenn
This discussion has been closed.
Replies
No - There is absolutely no difference between fnDestroy and bDestroy - the latter just makes the call to fnDestroy internally. Having said that, if you want to change the initialisation options of the table, then yes, this is required (including changing the columns etc). If you just want to load different data then use the fnReloadAjax plug-in.
> Is it better to blow the entire table away each time (replacing the DOM node with a new empty table)?
You need to call fnDestroy or bDestroy since DataTables holds an internal link tot he DOM nodes. If you don't your app will leak memory!
Allan
It appears that there is a new cookie created each time the DataTables instance is recreated. I think that sInstance may help here. I'm still looking...
Thanks for your prompt reply. In my case, each new tabular data can have different columns. So, I will indeed set bDestroy to true for successive renderings.
Regards,
Glenn
Should that be required? Or perhaps there is some bug in my code?
Thanks for your great work on DataTables and have a great weekend!
In theory no that shouldn't be required - however applying the original width can be a little tricky since I can only read the pixel value (unless you add the attribute width="100%"). So this is why there might be a problem. I have got a couple of unit tests that should test that, but it is possible that they aren't complete enough tests. If you could provide a test case showing the problem, that would be very useful.
Allan