PDA

View Full Version : How to access the component using itemId



rchavan
4 Mar 2010, 11:13 PM
Hi ,

I want to use the same component in the multiple tab but I'm facing the problem as I had given the ID for the component, I read that we can use the itemId but i'm facing the problem in accessing the component using itemId, can any one tell me how to access the component using the item id, Here is the sample code I'm using :

PostLoginPage.AbrvPatientInfoPanel = Ext.extend(Ext.Panel, {

initComponent:function() {
abrvInfoPanelConfig = {
store:abrvpatientInfoStore,
plain:true,
closable:true,
layout: 'form',
items:
[

{
height: '20%',
anchor: '100%',
xtype:'panel',
layout:'form',
region:'center',
labelWidth:200,
items:
[
{
xtype:'label',
itemId:'abrvLastName'
},}]

};

// apply config
Ext.apply(this, Ext.apply(this.initialConfig, abrvInfoPanelConfig));

// call parent

PostLoginPage.AbrvPatientInfoPanel.superclass.initComponent.apply(this,
arguments);

}//eo init component
});
Ext.reg('abrvPatientInfoPanel', PostLoginPage.AbrvPatientInfoPanel);

I want to access the component in red outside..

tobiu
4 Mar 2010, 11:42 PM
hi rchavan,

here is the example from the api-docs:



var c = new Ext.Panel({ //
height: 300,
renderTo: document.body,
layout: 'auto',
items: [
{
itemId: 'p1',
title: 'Panel 1',
height: 150
},
{
itemId: 'p2',
title: 'Panel 2',
height: 150
}
]
})
p1 = c.getComponent('p1'); // not the same as Ext.getCmp()
p2 = p1.ownerCt.getComponent('p2'); // reference via a sibling


another quite nice config for this accessing-problem is "ref".


kind regards,
tobiu

rchavan
5 Mar 2010, 12:36 AM
Hi thanks for the reply,

But I'm using the component another way i.e. registering the component and making the xtype to use it at the multiple places...

tobiu
5 Mar 2010, 12:54 AM
so?



p1 = c.getComponent('p1');


says parent.getChildComponentWithItemId(x).

as long as you know who the parent is, this is fine.
though "ref" is more flexible, since you can climb up the ownerCts further.


kind regards,
tobiu

rchavan
5 Mar 2010, 1:06 AM
HI,

I'm bit new to extjs,

I'm using above component as xtype in another panel so can you please tell me which one be the parent for my red marked component..

tobiu
5 Mar 2010, 2:46 AM
it is not written in your code -> there is only the constructor.

if you call


var c = new PostLoginPage.AbrvPatientInfoPanel({...});


or define the parent with


xtype : 'abrvPatientInfoPanel'


then that should be your parent to fetch.