PDA

View Full Version : context menu question



Mic1
12 Jul 2012, 4:54 PM
should this controller code work?:

init: function() {
'gridProd1' : {
render: function() {
Ext.getBody().on("contextmenu", Ext.emptyFn, null, {preventDefault: true});
},
itemcontextmenu : function( grid, record, item, index, event){
x = event.browserEvent.clientX;
y = event.browserEvent.clientY;
var menu = new ExtMVC.view.WizMenu();
menu.showAt([x, y]);
}
}
});
}

I am getting standard context menu when right-click on grid panel with alias 'gridProd1' - found the code snippet on StackOverflow - wanted to verify it should work. tia, Mic

scottmartin
12 Jul 2012, 5:27 PM
In the controller, I have this:



me.control({
'app-list-request button[action=deleteRequest]' : {
click : this.deleteRequest
}
});


in the view for the grid



initComponent : function () {
// assign columns
this.columns = colRequestsFull;

this.selModel = selModel;

this.addEvents('removeitem');
this.actions = {
removeitem : Ext.create('Ext.Action', {
text : 'Delete Request',
handler : function () {
this.fireEvent('removeitem', this.getSelected())
}, // controller.deleteRequest gets selection already
scope : this
})
};

var contextMenu = Ext.create('Ext.menu.Menu', {
items : [
this.actions.removeitem
]
});
this.on({
itemcontextmenu : function (view, rec, node, index, e) {
e.stopEvent();
contextMenu.showAt(e.getXY());
return false;
}
});

// apply parent
this.callParent(arguments);
},


Regards,
Scott.

Mic1
15 Jul 2012, 9:15 PM
got my code working with a 'gridpanel': { ... rather than specifying one panel. Have no idea why it would not communicate with the named gridpanel 'gridProd1' :-) Since I just work out I need to have a context-menu on all grids now it works out ok. Thanks, Mic

Mic1
16 Jul 2012, 1:07 PM
hey Scott marking you as best answer as my understanding of ext js increases with each one of your posts :-) thanks!