View Full Version : Need to delay window.print() until the grid completely renders the data

6 Aug 2010, 11:16 AM
I am using a GXT grid. I am loading the data using a loader instance. I tried to attach a listener to the grid using all events on Events class but none seem to be corresponding to the after load or afterRender event .... I am stuck trying to delay the window.print() functionality until the grid loads. Any help is appreciated.

PS. I also tried to attach the loadListener and the regularListener to the loader without any luck.

Colin Alworth
9 Aug 2010, 9:32 AM
When a ListStore's loader finishes loading, it fires an event which is caught by a LoadListener.loaderLoad method, which eventually fires a Store.DataChanged event from the ListStore. The GridView then listens to that event and calls onDataChanged, which, if the grid is ready to be displayed, fires a Events.Refresh event. Listen for that on your Grid's GridView instance.

I highly recommend just reading the code - looking into the ListStore would show the event it listens for in the Loader, and adding a breakpoint or searching the Grid files would show the rest of this.

Also: are you trying to use the GXT Grid class to print something out for the user? Aren't there better ways to have them get a hard copy of tabular data?

> PS. I also tried to attach the loadListener and the regularListener to the loader without any luck.
If the loader never fired an event, the something is probably wrong with how you are using it... Unless you mean to say that the listener went off too early.

9 Aug 2010, 12:12 PM
Colin ...I tried your suggestion by adding a listener to the grid instance as follows:

gridInstance.addListener(Events.Refresh, new Listener<GridEvent<BeanModel>>() {
public void handleEvent(GridEvent<BeanModel> be) {

but it does not trigger the print window. What am I doing wrong here ?

Colin Alworth
9 Aug 2010, 1:59 PM
It really will depend on when the loader finished - check my reply to your PS to look into what might be going on.

From what you are saying, either the loader isnt going off correctly/at all, which would stop the refresh event from happening. Also, if the loader finishes its work before the grid has draw, no refresh is required, as the grid was drawn correctly to begin with.

Can you post at least the basic flow of your app at this point?

10 Aug 2010, 6:30 AM
Thanks for your reply. Here is the flow of my application:

-- As soon as the user logs in, they land on a page
-- This page contains two tabs... each tab has a grid within its panel
-- each grid has print functionality and a pagination tool attached to it
-- only X records are displayed per page within the grid.
-- When the user clicks print button on any of the grids, it opens another window and loads all the rows within a grid.
-- I need to wait till all the rows are loaded onto the grid and rendered before I can call window.print().

If I cannot reliably find an event that is triggered after all data is loaded into the store and the grid finished rendering all its rows, there is no way I could call the window.print() that will work the way I would want it to.

Colin Alworth
10 Aug 2010, 7:05 AM
Hmm. Still not quite getting what I need.

It is extremely unlikely that a completely different GWT app (tabs, grids, etc) is going to affect this issue. What does your popup entry point do? How does it get data and draw the grid? That is the flow that is relevant for this discussion.

I suspect that your data has loaded before the grid is drawn, and so the grid's view never fires the Events.Refresh event. However, you say that you use a loader, suggesting that you should a) be seeing that event, and b) be seeing events from the loader. Have you tried placing breakpoints in GXT classes like the ListStore?

In lieu of summarizing how the app loads, post the code, and I can try reading through it. I don't know how much development you've done before, but your answers to me trying to help you are tending toward the useless...

10 Aug 2010, 9:50 AM
Thanks. I really appreciate your time and effort towards this thread. I am trying to give you a hawk eye view of the flow and trying not to feed you with entire code base.

Here is whats happening at a slightly greater detail:

When the user clicks on the print button, I am constructing a url with the required params and the history token (#print) and opening a window

we are using an MVP framework called MVP4G. It acts as the entry point for the application and triggers load of appropriate 'mvp4g module' based on the history token (we need to implement onPrint() method in this module to proceed further. All the required service handles required to make the rpc call are automatically injected and ready to be used at this point)

Within the onPrint() ... I am making an async call to the server to fetch the data I need to print ... onSuccess() of this call, I am constructing the List<ColumnConfig>,
the MemoryProxy as follows

MemoryProxy<BaseListLoadResult<BeanModel>> proxy = new MemoryProxy<BaseListLoadResult<BeanModel>>(listOfObjectsThatINeedToPrint);

The loader as follows
ListLoader<ListLoadResult<ModelData>> loader = new BaseListLoader<ListLoadResult<ModelData>>(proxy, new BeanModelReader());
and the store as follows
ListStore<BeanModel> store = new ListStore<BeanModel>(loader);

Creating the ContentPanel instance, grid instance and adding the grid to the the content panel as follows:

ContentPanel gridContentPanel = new ContentPanel();
Grid<BeanModel> grid = new Grid<BeanModel>(store, cm);

I also have a listener attached to the grid with the implemented handleEvent as follows

grid.addListener(Events.Attach, new GridAttachListener(loader));


public void handleEvent(GridEvent<BeanModel> be) {

At this point, the list I need to print is already in the memory. so like you said, data has loaded before the grid is drawn, and so the grid's view never fires the Events.Refresh event. Having said that, I do not see any events from the loader either. I hope this level of detail is sufficient to help move the discussion fwd.

10 Aug 2010, 9:55 AM
loader.addListener(Loader.Load, new Listener<LoadEvent>(){
public void handleEvent(LoadEvent le){
DeferredCommand.addCommand(new Command(){


I have not tested this but should do it.

10 Aug 2010, 11:22 AM
Thanks sven ... it worked. !