PDA

View Full Version : findParentByType not working?



eds2103
9 Nov 2011, 9:17 AM
I'm using ext-3.2.1

I have an extended Ext.grid.GridPanel registered with xtype 'mygrid'. That's all working. The grid has a property like this:


contextMenu: new Ext.menu.Menu({
items: [
{text: 'Copy selected to clipboard', handler: function() {
var v1 = this.findParentByType('mygrid');
var v2= this.parentMenu.findParentByType('mygrid');
}}
]
}),


Immediately after those two findParentByType calls, both v1 and v2 are null somehow. Since contextMenu is a property of the grid of xtype 'mygrid', doesn't that make the grid an ancestor of the menu item? Or at least of the menu, which i get with parentMenu for v2. i tested parentMenu and that works -- it's not null. I'm sure i spelled the xtype correctly. I also tried xtype 'grid' in case maybe out extended grid like wasn't registered yet with the new xtype.. that didn't work either. Any ideas what I'm doing wrong here?

Appreciate your help.

eds2103
9 Nov 2011, 10:11 AM
I think I know the problem. Merely assigning this menu to some arbitrary property of the grid does not make it a child of the grid in the component-hierarchy sense. Does anyone know how I can make this menu a child of the grid in that sense? (Without actly having it affect the look of the grid at all. It's supposed to be always invisible until someone right-clicks and it comes up like a context menu where they clicked.)

eds2103
9 Nov 2011, 11:13 AM
I came to this solution -- no longer using findParentByType --



listeners: {
contextmenu: function(event) {
var dsg = this;
this.contextMenu.findById('copyBtn').setHandler(function() {
var selections = dsg.getSelectionModel().getSelections();
var copyText = selections[0].data.id;
for (var i = 1; i<selections.length; i++) {
copyText += "\r\n" + selections[i].data.id;
}
Ext.copyToClipboard(copyText);
});
this.contextMenu.showAt(event.xy);
}
},
contextMenu: new Ext.menu.Menu({
items: [
{text: 'Copy selected to clipboard', id:'copyBtn'}
]
}),


Question: I had to do contextMenu.findById('copyBtn') because contextMenu.items.itemAt(0) didn't seem to work. There's also items.item('key') but how do i set the key? I have on PDF on learning extjs and that doesn't seem to be covered