How to refresh a table with open child rows without AJAX
How to refresh a table with open child rows without AJAX
Hello,
I have a datatable that is driven by an array, which is updated elsewhere. The table has child rows, and I need to refresh it without closing the rows, but can't figure out how. Currently, when the array changes, I go through the table data and update it to match by removing and adding rows, which is not ideal. Essentially there are two data sets, the array and the table... I have yet to figure out a way to keep child rows open with this setup. I've tried storing TRs and row IDs externally and "re-opening" them on draw or after updating, with and without timeouts, but it doesn't work or is dreadfully unreliable.
The next thing I can think of is to change it to use "ajax: function () { return my array }" and ajax.reload(), but I'm not sure or hopeful that this will keep open children open, either.
The next thing would be rewrite things to use only the table as a data source, but that will be a lot of work.
Is there a way to refresh a table using local array data (or another client-side source) while keeping child rows open?
Replies
instead of adding and removing rows, you should 'update' the row with your array of data.
in datatables 1.9.4 the function was called fnUpdate()
eg.
table.fnUpdate(arrayOfColumns, rowNumber);
maybe a newer function in 1.10, but the legacy functions still work.
If you update, the child row will stay open, but there is no function I know if that can update it. I have created some custom code to do so, and can share if you are interested in it.