We are using the excellent Tabulator JS library. We poll our server at intervals to refresh the data in our table. We are trying to achieve the following behaviour when this happens.
- Update the existing data in the table
- Add any new rows that "Match" the current filters
- Remove any rows that have changed and don't match the filters
- Keep the existing scroll position
- Keep any selected rows.
- If the filters are removed show the latest data.
There are 3 methods to update Tabulator
http://tabulator.info/docs/4.5/update
- SetData (we use this when we first fetch)
- updateData
- updateOrAddData (we use this on repeated fetches but row edits don't get filtered out)
- replaceData
In the documents is mentions that 'replaceData' will update existing table data with out resetting the scroll position or selected rows, this does not seem to be the case. 'updateData' does update the data and leaves the scroll pos and selected rows as is, BUT it does not apply the filters, for example if a row is updated out of the scope of the current filter it still shows?
Our code right now:
if (replace) {
table.updateOrAddData(data); //replaceData
} else {
table.setData(data);
}
We need the table to update and meet our requirements in my above points 1-6. I would expect one of the methods listed (replace, update) would do this and in the docs it seems they should, but in our tests this fails. How can we achieve the desired results?
We are using version 4.5 downgraded from 4.4.
Edit:
So for example if we update the table with data and one of the rows in the table does not exist in the new data, that update does not persist. Unless we use setData which resets the scroll position, undoes all selected rows and so on.
The latest version of Tabulator, 4.9, adds a refreshFilter function. This should accomplish most of your request.
My own testing also show that the sorters are also refreshed by this function.
table.refreshFilter();