refreshing data (items) in dynamic loaded datatable

Please give me advice what is the best way to load new data or the datatable. I would like to refresh data but I notice some problem:

  • Previously I used dtable.load(url) – the url contains proper start and count values – but data which was not present in http response was not deleted from datastore and still shown in table view
  • I try to user dtable.clearAll(true) (before calling load() or in onBeforeUpdate) – but in this situation the table is scrolled to the beginning and loosing selected rows.

Do You have better way to refresh items in datatable?

I make some snippet which shown the idea:

the snippet work fine, since data is static, if the data is dynamic (like in comment “NOTE” and in my environment) there is problem with records that are not present in server response – they are still displayed in data table, but should not.

The refreshing should preserver sorting order, filtering state and selection rows.

Hi @piotrek ,

By default, existing rows are not replaced by incoming data, but conjoined with it.
If you parse or load the array of data objects where some IDs match the existing data, fields of these records will be updated: https://snippet.webix.com/0wrt5myr
The same logic is valid for the dynamic loading: new data is added, existing records are updated, remaining stays untouched.

the record which is not present in data from server should not be shown

In such use-case, the full reloading is a fully valid option.
A realtime data updates (for a single data record/operation) can be also provided by WebSockets, but this technology is not suitable for managing a relatively big amount of data at once.

The following snippet has two additions to the original example: https://snippet.webix.com/fmzymg99

  • clearAll is called in the “soft” mode. It preserves the original URL set in the table.
    Here it is important because the clear datatable accepts the new URL as-is as a base data source.
    During further requests for data (if a user scrolls the data between full reloading), datatable will join current parameters to the base URL, which may lead to confusion between similar settings.
  • The scroll is restored from the previously used state after the data is loaded.

Still, there is one peculiarity of this way of data handling: as the empty datatable has the scroll position 0 (scroll always resets with the data), reloading will trigger two requests: the needed one and the additional request for the 1st data chunk (which will not affect the restored scroll state).