PDA

View Full Version : How to find out from the Grid that Store is loaded



whalethewise
27 Oct 2011, 12:12 PM
Hi

Store.load() is asynchronous. We need to do some actions within Grid after store is loaded.

Is there any ways for Grid to know that Store is loaded?

Thanks

davidcfox
27 Oct 2011, 1:33 PM
Have you tried listening for the "viewready" event and then performing your actions? I believe that this event is fired late enough that there is data in the store. They state in the documentation that this is the event you would listen for if you were wanting to select a default row. Here is the link to the viewready documentation for the grid panel: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.grid.Panel-event-viewready

netemp
27 Oct 2011, 9:12 PM
Store.load() is asynchronous. We need to do some actions within Grid after store is loaded. Is there any ways for Grid to know that Store is loaded?

The actions which you want to perform after loading of store can be called in the 'load' event of store (you can define this in the listeners of store). For more details - http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-event-load

O (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-event-load)ne other way of checking if the store has loaded or not is by using store.isLoading() - http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-method-isLoading

whalethewise
28 Oct 2011, 6:17 AM
The actions which you want to perform after loading of store can be called in the 'load' event of store (you can define this in the listeners of store). For more details - http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-event-load

O (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-event-load)ne other way of checking if the store has loaded or not is by using store.isLoading() - http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.Store-method-isLoading

Yes, it can be called from store.load() event. But Store doesn't know about its grids. You can get store from grid but not grid from store. It would be nice if Grid had some kind of 'load' event fired when grid's store is loaded.

mitchellsimoens
28 Oct 2011, 6:44 AM
In the Grid, listen for the Store's load event. If you need to do something on the Store that you need access to the Grid, then in that load listener, pass the instance of the Grid.

whalethewise
28 Oct 2011, 6:48 AM
Just to clarify, 'load' event from store bubbles up to 'grid'? And would you please give quick code example for 'then in that load listener, pass the instance of the Grid.' ?

Thanks
Paul

skirtle
28 Oct 2011, 7:04 AM
Ext.create('Ext.grid.Panel', {
initComponent: function() {
this.callParent();

this.mon(this.getStore(), 'load', this.storeLoaded, this);
},

storeLoaded: function() {
...
}
});

whalethewise
28 Oct 2011, 7:14 AM
Can't mark two answers as best but thank you very much both of you :)

Paul