PDA

View Full Version : How to access store object outside gridpanel



venu
24 Feb 2009, 1:45 AM
Hi,
I am writing a preconfigured class for Paging GridPanel. It has a button 'add' in its Top Toolbar. When i click on the 'add' button i am calling another function that will display a ExtJS FormPanel with form fields, and also i want to pass the store object to that screen.

I tried with below code but not working. Can anyone tell me the problem with this code. Removed some parts for shortining the code.

this is my code
----------------
var url = GLOBAL_URL+'/springdemo/diagnosis/list.do';
Ext.namespace('FMS.ux');
FMS.ux.Grid = Ext.extend(Ext.grid.GridPanel, {
initComponent: function(){
var config = {
id : 'id-diagnosis-grid',
store: new Ext.data.Store({
proxy : new Ext.data.ScriptTagProxy({url : url}),
reader: //reader data here,
columns : [ / columns data ],
tbar :
[
//Buttons for Add - Event Handling
new Ext.Toolbar.Button({
text: 'Add',
handler: function(){
//Here i want to pass the Grid store object to another function.
//But it is not able to access the store obejct.
new Create(this.store);
}
}),
]
};
Ext.apply(this, config);
Ext.apply(this.initialConfig, config);

this.bbar = new Ext.PagingToolbar({
pageSize: 5,
store: this.store,
displayInfo:true
});
FMS.ux.Grid.superclass.initComponent.apply(this, arguments);
},

onRender: function(){
FMS.ux.Grid.superclass.onRender.apply(this, arguments);
this.store.load({params:{start:0, limit:5}});
}
});
Ext.reg('diagnosisgrid',FMS.ux.Grid);
Need help in solving this problem.

Thx.
venu

Lloyd K
24 Feb 2009, 2:12 AM
In your example you don't give the button scope so it assumes the scope is the button:



tbar :
[
//Buttons for Add - Event Handling
new Ext.Toolbar.Button({
text: 'Add',
handler: function(){
//Here i want to pass the Grid store object to another function.
//But it is not able to access the store obejct.
new Create(this.store);
}
}),
]


Should be:



tbar :
[
//Buttons for Add - Event Handling
new Ext.Toolbar.Button({
text: 'Add',
scope: this,
handler: function(){
//Here i want to pass the Grid store object to another function.
//But it is not able to access the store obejct.
new Create(this.store);
}
}),
]


If you also give your Grid an id you can use Ext.getCmp() and simply use the store directly:



var store = Ext.getCmp('my_grid').store;

venu
24 Feb 2009, 5:19 PM
Thanks Lloyd.

Worked.