PDA

View Full Version : Call store listeners in Controller



mrhomer
23 May 2012, 12:03 AM
'GridStore': {
beforeload (http://docs.sencha.com/ext-js/4-1/#%21/api/Ext.data.AbstractStore-event-beforeload): this.storeBeforeLoad
load: this.storeLoadFinished
}

This is my code and nothing is happening. What is wrong?

vietits
23 May 2012, 12:13 AM
What is 'GridStore'? One thing to remember that store is not a component so you can't use <controller>.control() to handle store events directly.

mrhomer
23 May 2012, 12:14 AM
GridStore is the storeId

vietits
23 May 2012, 12:22 AM
As I wrote in my previous post, store is not a component so you can not use <controller>.control() with store. However, you can get reference to the store and then add event handler to it. Example:


init: function(){
var me = this;
me.control({
...
});
var store = Ext.StoreManager.lookup('GridStore');
store.on({
scope: me,
beforeload: me.storeBeforeLoad,
load: me.storeLoadFinished
});
me.callParent(arguments);
},
storeBeforeLoad: function(){
....
},
storeLoadFinished: function(){
....
}

Asaru
23 May 2012, 5:23 AM
We use a controller specifically for our stores.


Example:



Ext.define('app.controller.Stores', {
extend:'Ext.app.Controller',

// creates getter methods "this.get<NAME>Store()"
stores:[
'GridStore',
'Something'
]
init: function() {
var myGridStore = this.getGridStoreStore(),
mySomethingStore = this.getSomethingStore();

myGridStore.on('load', this.evh_gridStoreLoad);
myGridStore.on('beforeLoad', this.evh_gridStoreBeforeLoad);

},
evh_gridStoreLoad: function() {

},
evh_gridStoreBeforeLoad: function() {

}
};