1. #1
    Sencha User
    Join Date
    Oct 2009
    Posts
    95
    Answers
    3
    Vote Rating
    1
    Albareto is on a distinguished road

      0  

    Default Answered: What's the correct way to get the buttons from an Ext.window.Window?

    Answered: What's the correct way to get the buttons from an Ext.window.Window?


    Hi there,

    I have a Window, something like this:

    Code:
    var buttons = getButtons(),
        w = Ext.create('Ext.window.Window',
        {
             //config here...
            buttons : buttons
        });
    Then in an event I want to iterate over this buttons, I get the window there but how to get the buttons?

    I have seen that I can get the docked elements and from there the array of buttons, this is a bit overkilling in my opinion, I mean, the code would be like:

    Code:
    var buttons = [];
    Ext.Array.each(myWindow.getDockedElements(), function(de)
    {
        if (is in the bottom)
        {
              //check if it has buttons, if so then store them in the array
        }
    });
    In Ext 3.X there was a method in the window that returned the buttons, any idea how to get them now?

    Thanks!

  2. 1 - Give an itemId to your window:
    PHP Code:
    Ext.create('Ext.window.Window',{
       
    itemId'mywindow',
       ...
    }); 
    2- Do whatever you need to do to generate the buttons

    3 - Use Ext.ComponentQuery.query to retrieve the buttons from the window:
    If the buttons are in a toolbar, you can use:
    PHP Code:
    Ext.ComponentQuery.query('myWindow toolbar button'); 
    The code above will return an array of all buttons that are inside a toolbar in your window.

  3. #2
    Sencha User
    Join Date
    Jul 2011
    Posts
    20
    Answers
    1
    Vote Rating
    0
    ezriel is on a distinguished road

      0  

    Default


    Assign id value to the button and then use Ext.getCmp("button_id")

  4. #3
    Sencha User
    Join Date
    Oct 2009
    Posts
    95
    Answers
    3
    Vote Rating
    1
    Albareto is on a distinguished road

      0  

    Default


    Thanks for the reply, unfortunately I cannot do that as my buttons are generated dynamically so I don't know the ids of them or how many are going to be.

    The idea behind this code is to disable them when some action is performed.

  5. #4
    Sencha User
    Join Date
    Oct 2009
    Posts
    95
    Answers
    3
    Vote Rating
    1
    Albareto is on a distinguished road

      0  

    Default


    Also I said that in 3.X there was a method to get them, that's not entirely true, but you could do window.buttons to retrieve them, maybe this is because buttons was not only a config but also a property of the Component? Anyway, the point is that in ExtJS 4 this is not the case anymore.

  6. #5
    Sencha User
    Join Date
    May 2011
    Location
    Ukraine, Rivne
    Posts
    247
    Answers
    44
    Vote Rating
    42
    redraid has a spectacular aura about redraid has a spectacular aura about redraid has a spectacular aura about

      0  

    Default


    Try something like this (change grid to window):
    PHP Code:
    // Generated buttons
    {
        
    text'Btn1',
        
    btnrole'role1'
    },
    {
        
    text'Btn1',
        
    btnrole'role2'
    }
    //...

    // disable/enable buttons by role
    // for example in selectionchange event
    selectionchange: function (gridselectedeOpts) {    
    var 
    me grid,
            
    selCount selected.length,
            
    role1Btns me.query('button[btnrole=role1]'),
            
    role2Btns me.query('button[btnrole=role2]');

    // Disable role1 buttons if selection empty
        
    Ext.Array.forEach(role1Btns, function (btn) {
            
    btn.setDisabled(selCount == 0);
        });

    // Disable role2 buttons if selection not empty
        
    Ext.Array.forEach(role2Btns, function (btn) {
            
    btn.setDisabled(selCount != 0);
        });

    //wbr

  7. #6
    Sencha User loiane's Avatar
    Join Date
    Aug 2009
    Posts
    183
    Answers
    7
    Vote Rating
    52
    loiane is a jewel in the rough loiane is a jewel in the rough loiane is a jewel in the rough

      0  

    Default


    1 - Give an itemId to your window:
    PHP Code:
    Ext.create('Ext.window.Window',{
       
    itemId'mywindow',
       ...
    }); 
    2- Do whatever you need to do to generate the buttons

    3 - Use Ext.ComponentQuery.query to retrieve the buttons from the window:
    If the buttons are in a toolbar, you can use:
    PHP Code:
    Ext.ComponentQuery.query('myWindow toolbar button'); 
    The code above will return an array of all buttons that are inside a toolbar in your window.
    Sencha/Java evangelist
    Author of ExtJS 4 First Look and Mastering Ext JS books
    English blog: http://loianegroner.com
    Portuguese blog: http://loiane.com
    Sencha Examples: https://github.com/loiane

  8. #7
    Sencha User
    Join Date
    Oct 2009
    Posts
    95
    Answers
    3
    Vote Rating
    1
    Albareto is on a distinguished road

      0  

    Default


    Thanks for all the replies, actually Ioiane's answer was what I was looking for. Redraid, with that I receive Elements, I was more looking for Component, I actually didn't realized there was a ComponentQuery class!

    This is the solution for my case:
    Code:
    var buttons = Ext.ComponentQuery.query('toolbar button', myWindow);
    Could also use the window id as you suggested, I don't know what would be better as I have the Window Object in my method as well.

    Thanks again.

  9. #8
    Sencha User
    Join Date
    May 2011
    Location
    Ukraine, Rivne
    Posts
    247
    Answers
    44
    Vote Rating
    42
    redraid has a spectacular aura about redraid has a spectacular aura about redraid has a spectacular aura about

      1  

    Default


    query method have all descendants of AbstractContainer, window descendant of container

  10. #9
    Sencha User
    Join Date
    Oct 2009
    Posts
    95
    Answers
    3
    Vote Rating
    1
    Albareto is on a distinguished road

      0  

    Default


    That's true, I could just do

    Code:
    myWindow.query('toolbar button');
    with the same result.

    This forum is great, with every answer I learn something new.

    Thanks for your input

Thread Participants: 3

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi