Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs 4 How to get id of parent Component?

Tags:

extjs4

I have multiple fieldset. And have Button inside each fieldset in Extjs 4. I want to get fieldset id on the button click event, so that i can know from which fieldset the button was clicked

How do i get this?

    {
     xtype:'fieldset',
     id:'fs1',
     items:[{
     xtype:'button',
     id:'b1',
     handler:function(){
       // here i want to get fieldset's id because because fieldset and button were added dynamically.
      }
     }]
    }

Thanks, Kunal

  Actual Code:

  Ext.define('My.Group',{   
xtype : 'fieldset',
 config: {
     title:'Group' + i.toString(),
     id : '_group' + i.toString()       
 },
     constructor: function(config) {
     this.initConfig(config);

   return this;
 },

collapsible : true,
frame : false,
boder : false,
items : [ {
xtype : 'button',
text : 'Add KeyWord',
id: 'btn',
width : 100,
handler : function(button,event) {

     var fieldset = button.findParentByType('fieldset');
     var fieldsetsID = fieldset.getId();

    console.log(fieldset);

    Ext.getCmp(fieldsetId).insert(2, rangeField);
    Ext.getCmp(fieldsetsID).doLayout();
}

 }, {
 xtype : 'button',
 text : 'Add Range Type',
 width : 100
} ]
});

and i am calling this function on button click

 handler : function() {
        i=i+1;
        var group = new My.Group({
            title:'Group' + i.toString(),
            id : '_group' + i.toString()                
        });

        console.log(group);
        Ext.getCmp('_aspanel').insert(i, group);                
        Ext.getCmp('_aspanel').doLayout();  
like image 863
Kunal Avatar asked Jul 14 '11 10:07

Kunal


2 Answers

I've implemented handler properly.

{
    xtype:'fieldset',
    id:'fs1',
    items:[{
        xtype:'button',
        id:'b1',
        handler:function(btn){
            // Retrieve fieldset. 
            var fieldset = btn.up('fieldset');
            // Retrieve Id of fieldset.
            var fieldsetId = fieldset.getId();
        }
    }]
}

In that case try this:

button.up("[xtype='fieldset']")

like image 98
Zango Avatar answered Nov 02 '22 22:11

Zango


Ext.onReady(function() {
  var panel = Ext.create('Ext.panel.Panel', {
      items:  {
        xtype:'fieldset',
        id:'fs1',
        items:[{
          xtype:'button',
          id:'b1',
          handler:function(b,e){
            var fieldset = b.findParentByType('fieldset');
            var fieldsetID = fieldset.getId();
            console.log(fieldsetID);
          }
        }]
      },
      renderTo: document.body
  });
});

Notice, that once you have fieldset variable, you can actually add items to this container directly, without need to use its ID

like image 5
Mchl Avatar answered Nov 02 '22 21:11

Mchl