Adam Bergeron
Adam Bergeron

Reputation: 525

Have Widget reload/refresh data every 2 minutes

I have a page showing room status via color (Green = Available, Red = Booked, etc). The goal is that users can leave that page open and when someone else edits the database (via a table on a separate page) the status page will update automatically.

Manually refreshing the page works, but an automated option would be best.

It doesn't have to be instant, but if I could tell the page to refresh automatically every "2 minutes" or something like that, that would be great.

I'm not sure if it would make the most sense to just have some kind of client side code running, or if there is maybe something a little more elegant where you can tell the widget itself to refresh automatically.

Thank you for your help!

Upvotes: 0

Views: 999

Answers (2)

Ali Ibrahim
Ali Ibrahim

Reputation: 173

I would suggest adding the following scripts to the onAttach and onDetach events for your page. Make sure you set the data source for the page to the one you want to reload. The idea is to load the data source while the page is showing every two minutes.

onAttach:

window.reloadId = setTimeout(function() { widget.datasource.load(); }, 2 * 60 * 1000);

onDetach:

clearTimeout(window.reloadId);

Upvotes: 0

Adam Bergeron
Adam Bergeron

Reputation: 525

Thank you Ali, Tony and Morfinismo!

I was able to get it to work with the following:

onAttach:

window.reloadId = setInterval(function() { widget.datasource.load(); }, 2 * 60 * 1000);

onDetach:

clearTimeout(window.reloadId);

Upvotes: 1

Related Questions