Results 1 to 2 of 2

Thread: How to target docked button in panel?

  1. #1
    Sencha Premium Member
    Join Date
    Jan 2012
    Posts
    15
    Vote Rating
    1
      0  

    Default How to target docked button in panel?

    If I have a panel with buttons defined in the buttons config, how can I target those buttons later?

    Code:
    {
        id: 'somePanel',
        xtype: 'panel',
        buttons: [{
            id: "myButton",
            xtype: "button"
        }]
    }
    Last edited by skirtle; 20 Sep 2012 at 4:46 PM. Reason: Fix formatting

  2. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,791
    Answers
    585
    Vote Rating
    394
      0  

    Default

    I'd avoid assigning your components ids if I were you.

    The easiest way is probably to use a Component Query. You can query for them in a number of ways depending on the circumstances but itemId is a common choice:

    Code:
    Ext.define('MyPanel', {
        extend: 'Ext.panel.Panel',
    
        buttons: [{
            itemId: 'myButton',
            xtype: 'button'
        }],
    
        initComponent: function() {
            this.callParent();
    
            // Store a reference to the button rather than repeating the query every time
            this.saveButton = this.down('#myButton');
        },
    
        ...
    
        // Some arbitrary method that needs a reference to the button
        myMethod: function() {
            var saveButton = this.saveButton;
            ...
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •