How to synchronize two table views between two sessions
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;
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.
wt-not-synchronizing-table-views.png (30.3 KB)
I can see that calling session-> rereadAll() can cause all the underlying objects to get reloaded. Is this what I need to do?
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
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