PDA

View Full Version : Scoping help needed...



deccard
22 Feb 2008, 4:01 AM
I'm trying to derive my own editorGrid widget from the EditorGridPanel - all is working well except a [hopefully minor] problem with scoping ..

The lines commented out are all working and all renders and works as required - the problem is that i want a button on the top toolbar of the grid to add a row to the grid [see 'add item' in the code ] - to do this i need to get a handle to the store of the grid, but i'm struggling to get the correct scope.

Any help greatly appreciated.



Ext.aurora.soGrid = Ext.extend(Ext.grid.EditorGridPanel, {
initComponent:function() {
Ext.apply(this, {
frame : false,
....
.....
store: new Ext.data.SimpleStore({
fields: [
{name: 'image'},
{name: 'code'},
{name: 'quantity'},
{name: 'total'}
]
}),

cm: new Ext.grid.ColumnModel([
.....
......
]),
tbar:[
{xtype: "xProductPicker"},
{
text: "Add Item",
iconCls: "add",
scope: Ext.aurora.soGrid.prototype, // doesn't work
//scope: Ext.aurora.soGrid.superclass, // doesn't work either...
handler: function(){
var p = Ext.data.Record.create([
{ image: "new image"},
{ code: "xxxx"},
{ quantity: 23},
{ total: 100}
]);
this.stopEditing();
var st = this.getStore(); // returns null
console.log(st); // null
console.log(this); // returns what looks like the grid
console.log(this.getStore()); // null even though i can see the method in the 'this' object in firefly
st.insert(0, p);
this.startEditing(0, 0);
}
}
]
}); // e/o apply

Ext.aurora.soGrid.superclass.initComponent.apply(this, arguments);

} // e/o function initComponent
,onRender:function() {
Ext.aurora.soGrid.superclass.onRender.apply(this, arguments);
} // e/o function onRender
});
Ext.reg('xStockOrderGrid', Ext.aurora.soGrid);

evant
22 Feb 2008, 4:22 AM
You're just referencing the type, not the instance:



scope: this


BTW, you don't have to provide a scope.

deccard
22 Feb 2008, 4:28 AM
thanks evant.