View Full Version : Notification when a grid is finished drawing

6 Oct 2011, 5:22 PM
Does anyone know how to detect when the grid is fully drawn on a page?

I have a large grid that I have split across pages using a PagingToolBar. One of the columns is a set of checkboxes that I set up the same way that the GridPlugins demo in the Ext GWT Explorer does it.

As I go from page to page, the checkboxes don't maintain state. To get around this, I'm saving the checkbox states in a list, but I find I need to wait until the grid for a page is completely redrawn before I can reset the checkboxes using the CheckBoxSelectionModel select(boolean keepExisting, M...) method.

Right now when I go from page to page, I'm using a 3 second timer before I update the checkboxes. I'd rather do it when I get some kind of notification that the page is fully drawn.

Anyone got a clue?


Colin Alworth
8 Oct 2011, 3:32 PM
Quickest way I can think of is to modify whatever is adding the items to the store - add a Scheduler.get().scheduleFinally command to apply the checks.

The logic here is that when you add the items to the store (possibly as a result of a Proxy returning data to a Loader, or possibly your own custom code calling store.add), this will trigger an event which tells the Grid to draw the items.

There is no way to _generally_ tell when 'the page is fully drawn', because you might have data loading from multiple sources, or expect some user interaction to start things off. Instead, is it best to decide what event or method getting called means that enough has finished for some task to occur.

In this case, we want to run code after data has been added to the store, and the grid redraws. One option would be to just call store.add (or callback.onSuccess if writing a custom proxy), and follow that up with your checkbox code. Another option would be to schedule your code to run after the load has finished (the GWT class Scheduler has several ways of doing this, either in the current event loop step, or in a later one).

10 Oct 2011, 10:47 AM
Thanks for the info, Colin.

What I ended up doing was subclassing PagingToolBar, and then overriding onLoad(LoadEvent event). After calling super.onLoad(event) in the overridden method, I found that the grid was in a state where I could restore the checkboxes.

A very simple solution, but it took me hours of fiddling around to figure it out.

Steve Sinai