ExtJs 4 reference to toolbar button in grid
i want to define a ref inside the controller to enable/disable the delete buitton on selection change. But i don't get it right, so the getDelButton()-Method delivers undefined. PLease help...
Controller:
refs:[
{ ref: 'tabPanel', selector: 'viewport > tabPanel' },
{ ref:开发者_StackOverflow社区 'grid', selector: 'tabPanel > usermanagementgrid' },
{ ref: 'delButton', selector: 'grid > button #delete'}
],
...
this.getDelButton().setDisabled(false);
View definition:
dockedItems: [{
xtype: 'toolbar',
items : [ {
xtype: 'button',
id: 'delete',
iconCls: 'drop-add',
text: 'Add',
tooltip: 'Press to add a new user.',
action: 'addUser',
scope: this,
},
Thanks in advance...
You likely have 3 problems with your selector:
- You should not have a space between the component and the id selector. Use:
button#delete
. - As nscrob mentioned you will likely need to use
gridpanel
instead ofgrid
. - The
button
is NOT a direct child ofgrid
. It is most likely a direct child oftoolbar
in this case. What this means is you must do something more like:gridpanel > toolbar > button#delete
ORgridpanel button#delete
.
In reference to #3 above, the >
selector means DIRECT CHILD of parent. That means literally a child of the parent, not just a component somewhere down the nesting chain. If you just want to pull a button in your gridpanel
then use gridpanel button
. This will search through all of gridpanel
's children and within all those children to find anything matching button
. Be aware however, that using it this way will return ALL buttons within the gridpanel
(unless of course you specify the id).
Lastly, using your console in firebug will help you IMMENSELY. Open firebug, and in the console you can run commands. So, load up the grid and run the following command:
Ext.ComponentQuery.query('gridpanel > toolbar > button#delete')
and see what gets returned. This way you don't have to keep going back and forth from your code and refreshing the browser window. Keep in mind that query()
returns an array.
i had a similar problem, it turned out to be the grid selector, normally you the selector uses xtype and the grid has either grid or gridpanel. Try using selector: 'gridpanel >button #delete'
Check the itemId property.
精彩评论