How to synchronize two table views between two sessions

Added by Mark Petryk 6 months ago

I have a WTableView that shows my data. When I load this view on one browser on one computer, I would like to save the underlying data (in the back-end SQL) and then cause every other connected browser to reload that same table view and see the updated data. But, for some reason calling;

model.setQuery(query)
model.reload()

None of that works. On the primary TableView, the browser where the back-end data was updated, the TableView updates properly. But, on all the other connected browsers, even though they are being refreshed, they do not show the updated back-end data.

I've tried requerying the query, reloading the model. Short of completely reconstructing the table view I'm not sure what to do?

One adverse affect is I don't want to destroy any custom sorts the users have applied to their table views.

Right now, if the user hits 'refresh' on their browser, and completely reloads the page, then, of course, the TableView has the right data in it. But, that's not really feasible nor practical.

Attached is an image of what I'm talking about.


Replies (3)

RE: How to synchronize two table views between two sessions - Added by Mark Petryk 6 months ago

I can see that calling session-> rereadAll() can cause all the underlying objects to get reloaded. Is this what I need to do?

RE: How to synchronize two table views between two sessions - Added by Korneel Dumon 6 months ago

Hi Mark,

your model in this example will be a different instance for each session, so it's correct that reloading will only affect the current session.
To propagate the fact that things have changed you can go through the WServer object, which manages all the sessions. If you override WServer, you can add your own functionality to allow one session to notify the others. The wt-example 'simplechat' can give you an idea of how it's done.

Things to be aware of: * for a session to be able to receive server updates, you must have called WApplication::enableUpdates (e.g. in the application constructor) * the best way to apply an update in other sessions is to use WServer::post (rather than grab the lock of the other session) * call WApplication::triggerUpdate to propagate your changes to the UI

RE: How to synchronize two table views between two sessions - Added by Korneel Dumon 6 months ago

Oops, something went wrong with my bullets :)

Things to be aware of:
  • for a session to be able to receive server updates, you must have called WApplication::enableUpdates (e.g. in the application constructor)
  • the best way to apply an update in other sessions is to use WServer::post (rather than grab the lock of the other session)
  • call WApplication::triggerUpdate to propagate your changes to the UI

(1-3/3)