-
24 Sep 2012 1:59 AM #1
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:
Then in an event I want to iterate over this buttons, I get the window there but how to get the buttons?Code:var buttons = getButtons(), w = Ext.create('Ext.window.Window', { //config here... buttons : 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:
In Ext 3.X there was a method in the window that returned the buttons, any idea how to get them now?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 } });
Thanks!
-
Best Answer Posted by loiane
1 - Give an itemId to your window:
2- Do whatever you need to do to generate the buttonsPHP Code:Ext.create('Ext.window.Window',{
itemId: 'mywindow',
...
});
3 - Use Ext.ComponentQuery.query to retrieve the buttons from the window:
If the buttons are in a toolbar, you can use:
The code above will return an array of all buttons that are inside a toolbar in your window.PHP Code:Ext.ComponentQuery.query('myWindow toolbar button');
-
24 Sep 2012 2:21 AM #2
Assign id value to the button and then use Ext.getCmp("button_id")
-
24 Sep 2012 2:25 AM #3
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.
-
24 Sep 2012 2:29 AM #4
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.
-
24 Sep 2012 3:24 AM #5
Try something like this (change grid to window):
//wbrPHP Code:// Generated buttons
{
text: 'Btn1',
btnrole: 'role1'
},
{
text: 'Btn1',
btnrole: 'role2'
}
//...
// disable/enable buttons by role
// for example in selectionchange event
selectionchange: function (grid, selected, eOpts) {
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);
});
}
-
24 Sep 2012 3:29 AM #6
1 - Give an itemId to your window:
2- Do whatever you need to do to generate the buttonsPHP Code:Ext.create('Ext.window.Window',{
itemId: 'mywindow',
...
});
3 - Use Ext.ComponentQuery.query to retrieve the buttons from the window:
If the buttons are in a toolbar, you can use:
The code above will return an array of all buttons that are inside a toolbar in your window.PHP Code:Ext.ComponentQuery.query('myWindow toolbar button');
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
-
24 Sep 2012 3:44 AM #7
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:
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.Code:var buttons = Ext.ComponentQuery.query('toolbar button', myWindow);
Thanks again.
-
24 Sep 2012 3:51 AM #8
-
24 Sep 2012 3:57 AM #9
That's true, I could just do
with the same result.Code:myWindow.query('toolbar button');
This forum is great, with every answer I learn something new.
Thanks for your input


Reply With Quote