PDA

View Full Version : How to bubble an event from Ext.data.Store ?



viniciuscs
5 Feb 2012, 1:57 PM
I'm working on a grid panel and i need such an event that get fired after the store associated with it has finished to load the data. After tried the 'viewready', 'afterrender' and 'afterlayout' events of the panel itself with no success then i started to look on the events of the store. The 'datachanged' event is perfect and works for me but i didn't find a way to bubble it to my grid. The store has the 'enableBubble' method, but not the 'getBubbleTarget' since it doesn't inherits from Ext.AbstractComponent.


store: {
fields: [ 'dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb' ],

initComponent: function() {
this.callParent();
this.enableBubble('myevent');
},

getBubbleTarget: function() {
console.log('getBubbleTarget');
return Ext.ComponentQuery.query('mygridpanel');
},

listeners: {
datachanged: function(store, options) {
this.fireEvent('myevent');
}
}
}


The "console.log('getBubbleTarget');" line on 'getBubbleTarget' method above is never reached and neither the grid listener for 'myevent'.

Someone can tell me what am i doing wrong? Or even an event from the grid panel that works on this scenario and i haven't tested yet.

viniciuscs
5 Feb 2012, 5:12 PM
I did noticed some mistake made on the previous post. Ext.data.Store doesn't has an 'initComponent' method so i tried to call the 'enableBubble' using a constructor as listed below but again, without success.


store: {
fields: [ 'dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb' ],

constructor: function(config) {
var me = this;


console.log('store constructor');


me.callParent(arguments);
me.initConfig(config);
me.enableBubble('datachanged');


return this;
}
}

vietits
5 Feb 2012, 6:27 PM
Let have a try with bubbleEvents config.


store: {
fields: [ 'dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb' ],

bubbleEvents: ['myevent'],

getBubbleTarget: function() {
console.log('getBubbleTarget');
return Ext.ComponentQuery.query('mygridpanel');
},

listeners: {
datachanged: function(store, options) {
this.fireEvent('myevent');
}
}
}

viniciuscs
6 Feb 2012, 2:25 PM
bubbleEvents is a config option of Ext.container.AbstractContainer and isn't available for Ext.data.Store.

vietits
6 Feb 2012, 3:26 PM
No, bubbleEvents is a config of Ext.util.Observable (see code below) and this class is used as mixin in Ext.data.AbstractStore. So, it will be available with Ext.data.AbstractStore and its extendings.

Constructor of Ext.util.Observable:


constructor: function(config) {
var me = this;


Ext.apply(me, config);
if (me.listeners) {
me.on(me.listeners);
delete me.listeners;
}
me.events = me.events || {};

if (me.bubbleEvents) {
me.enableBubble(me.bubbleEvents);
}
},


Though it also calls enableBubble() but this is called when constructing the store object in this case and before any call to enableBubble() you do with your code.

I have tried the code I supplied in the previous post and the getBubbleTarget() was reached well. Let have a try.

viniciuscs
6 Feb 2012, 3:56 PM
very nice vietits, it's working now! thnks.



store: {
bubbleEvents: [ 'datachanged' ],
fields: [ 'dom', 'seg', 'ter', 'qua', 'qui', 'sex', 'sáb' ],

getBubbleTarget: function() {
return Ext.ComponentQuery.query('mypanel')[0];
}
},


listeners: {
datachanged: function(store, options) {
console.log('works now');
}
}


By the way, i'm using your 'Its.grid.column.Component' in this grid i'm working on to render panels inside the cells. And this thread had started because i want to set the height of the panels (consequently the rows) to fill all available space in the grid. This grid will have a variable but limited number of rows ( 4-6 ). Do you know an easier way to achieve this? thks one more time.

vietits
6 Feb 2012, 6:23 PM
Hi viniciuscs,

I am sorry. I have no solution for your question right now.