View Full Version : itemcontextmenu - MenuItem Handler Action misfiring.

2 Nov 2011, 1:09 PM
I have the following controller code.

Ext.define('Myapp.controller.InstallGroup', {
extend : 'Ext.app.Controller',

views: ['installgroup.Add'],

refs : [ {
ref : 'physicalLayout',
selector : 'physicallayout'
ref: 'addInstallGroupWindow',
selector: 'addinstallgroupwindow',
autoCreate: true,
xtype: 'addinstallgroupwindow'
} ],

init : function() {
'physicallayout': {
selectionchange: this.onInstallGroupSelect,
itemcontextmenu: this.onItemContextMenu

onItemContextMenu: function(view, record, item, index, event, options) {
var tmpMenu = [];

tmpMenu.push({ text: 'Add Install Group', icon : '/public/javascripts/extjs/examples/shared/icons/fam/add.gif', handler: this.addInstallGroup(this) });
tmpMenu.push({ text: 'Delete Install Group', icon : '/public/javascripts/extjs/examples/shared/icons/fam/delete.gif', handler: this.deleteInstallGroup });

var menu = Ext.create('Ext.menu.Menu', { items: tmpMenu });

addInstallGroup : function(parent) {
console.log("In add Install Group");
var physicalLayout = parent.getPhysicalLayout();
var rec = physicalLayout.getSelectionModel().getSelection()[0];

deleteInstallGroup: function() {
console.log("In delete install group");


I have the itemcontext menu show up on a right click. The itemcontextmenu has two menu items "add" and "delete" each with its own handler. What I am seeing in my application is that the handler function for the add menu item (which is the first of two menu items) gets fired, as soon as the menu shows up and not when the menu item is actually selected.

Any ideas on how to solve this appreciated. BTW, I am using extjs-4.0.2a.

Thanks in advance.

3 Nov 2011, 8:26 AM
The handler on the add menu item is like this:

handler: this.addInstallGroup(this)

And having the '(this)' will automatically call it. You need to remove that and then it won't fire unless it is clicked on.