PDA

View Full Version : another scope problem



sofway
23 Feb 2011, 7:19 AM
hi,

i have a gridpanel with a

tbar: [{
text: 'Add',
handler: function(button){
console.log(this);
}

the problem is that i need a reference to the grid inside the button handler.
in the example, this is a reference to a window, and if i add scope: this to the button, it doesnt get the grid.

The idea is to get a grid with a fast reference, not with a Ext.getCmp('idGrid');

thanks

danguba
23 Feb 2011, 7:37 AM
Have you tried adding

scope: myGridwhere myGrid is reference to grid?

Or you might want to use createDelegate (http://dev.sencha.com/deploy/dev/docs/?class=Function&member=createDelegate) to set scope

sofway
23 Feb 2011, 7:41 AM
thanks danguba,

the problem is that i dont have myGrid var. It is a var grid = Ext.extend(Ext.grid.GridPanel....

do i have to use scope: grid ???
will it be right if i have to make several instances of grid?
thanks

danguba
23 Feb 2011, 7:46 AM
Can you paste your code sample?

You might even try to use this.ownerCt.ownerCt to access grid from button without setting it's scope but I dislike this solution.

sofway
23 Feb 2011, 7:51 AM
sure,




App.taxes = Ext.extend(Ext.grid.GridPanel,{
height: 200,
store: new Ext.data.ArrayStore(),
tbar: [{
text: 'Add',
handler: function(button){
// here i want to get a reference to the grid instance
}



do i have to use App.taxes inside handler ??? what happend if i make 3 instances of App.taxes?

danguba
23 Feb 2011, 8:03 AM
App.taxes = Ext.extend(Ext.grid.GridPanel, {
height: 200,
store: new Ext.data.ArrayStore(),
tbar: [{
text: 'Add',
handler: function(button){
this.ownerCt.ownerCt // <-- should have reference to grid
}
}]
});

and I think you cannot use App.taxes since App.taxes is a class and you need the instance of it

sofway
23 Feb 2011, 11:45 AM
your solution works perfect.
Thanks danguba

danguba
23 Feb 2011, 12:21 PM
I'm glad I was able to help