PDA

View Full Version : Auto refresh of a Grid Data



chazzz2473
26 Jan 2010, 1:55 AM
Hello everyone, i'm quite new to Ext GWT, and i'm trying to figure something out.

In my app, I use a Grid to display some data which is loaded with a RpcProxy.
The data of the grid may be changing on the Server side, and i need to refresh this list everytime it does.

How can this be done in a clean way ? I couldn't find a way to refresh the list every X seconds, and I couldn't find a way to trigger the reload via a listener either.

Thanks in advance for your help, and sorry for my English, I'm french :)
Let me know if you need any more information.

Chazzz

Edit : Using 2.1.0, by the way

Roddarn
26 Jan 2010, 3:24 AM
Hi.

You could use the timer to schedule a load. This should reload your store every 60 seconds.
(It's not tested, so I guess there are bugs in my small example)


Timer timer = new Timer() {
public void run() {
grid.getStore().getLoader().load();
}
};
timer.schedule(1000 * 60);

chazzz2473
26 Jan 2010, 4:14 AM
Thanks a lot, that is exactly what i was looking for.

Seems like if you want the timer to refresh itself like this :

final Timer timer = new Timer() {
public void run() {
loader.load();
schedule(1000);
}
};
timer.schedule(1000);

The loader needs to be final. No idea why though.

Arno.Nyhm
29 Jan 2010, 9:38 AM
final, because the call of the loader in run is then later and thats why the loader object should not change any more.

terciofilho
29 Jan 2010, 10:54 AM
Better:



final Timer timer = new Timer()
{
public void run()
{
loader.load();
}
};
timer.scheduleRepeating(1000 * 60);

uinewbie
5 Jun 2011, 10:43 PM
Hi, I have pretty much the same setup as the OP and have the timer working. However, is there a way to not use the timer and only refresh the Grid when there's an update on the server side? (i.e., push notification)

terciofilho
10 Jun 2011, 12:03 PM
Sure you can, but you need a comet implementation. Take a look at: http://code.google.com/p/gwt-comet/