PDA

View Full Version : Grid toolbar docked menu items- get grid reference, How?



klodoma1
19 Mar 2012, 8:03 AM
Hi all,

I am having the following code:- a grid with a toolbar, and on the toolbar there is a splitbutton, which has a menu. Here is a screenshot:

32900

In ext3: I was getting the reference to the main grid by the following code:

button.findParentByType('grid')....

In ext4: I tried the same, but when I click the "New" button it works, but if I click any of the menu items it does not work anymore. I have the feeling that the menu is does not have the grid parent at all.

QUESTION: how can I get the reference to the grid when I click the menu items???
The fix id solution and ext.getCmp() is excluded), it's not appliable to my application.




var toolbar new Ext.Toolbar({
items : [ {
xtype : "splitbutton",
text : "New",
iconCls : "icon-insert",
tooltip : "Add Field",
tooltipType : "title",
handler : function(button) {
//OK this works
button.findParentByType('grid').someFunction()
},
menu : new Ext.menu.Menu({
items : [ {
text : Ext.ux.Translations.get('LB_FIELD'),
iconCls : 'icon-field-add',
handler : Ext.bind(function(button) {
//NOT OK, this does not work ????
button.findParentByType('grid').someFunction()
}, unit)
}]
})
}]
});


var grid = Ext.create('Ext.grid.Panel', {
store: store,
columnLines: true,
columns: [
...
],
dockedItems: [
toolbar
],
);

mitchellsimoens
19 Mar 2012, 11:43 AM
You need to go up to the menu and then the menu has a reference to the float parent which is going to be the button. There you can get the grid.

klodoma1
20 Mar 2012, 1:51 AM
Thanks for your answer!
It does not make much sense imo, but anywhay, here is the piece of code which I hope will help others:

Reference to the grid:

var grid = button.findParentByType('menu').floatParent.findParentByType('grid')

klodoma1
21 Mar 2012, 2:39 AM
You need to go up to the menu and then the menu has a reference to the float parent which is going to be the button. There you can get the grid.

I've just upgraded to ExtJs4-rc1 and it's not working anymore. I'm getting really pissed of with migration to Extjs4. Is there some consistency between the releases?

How is the ExtJs4-rc1 "way" of solving the original question?

klodoma1
21 Mar 2012, 2:49 AM
Just to answer to my own frustration:


button.findParentByType('grid')
works again in RC1.

Question on Extjs team:
- how will be the final version work in case Extjs 4.1?

:-/