PDA

View Full Version : Problems with rowcontextmenu



karga
2 Aug 2009, 3:11 PM
Hi,

I'm having some trouble creating a contextmenu with the rowcontextmenu-event.. The standard contextmenu still appears, on top of my contextmenu

My code:


rowcontextmenu: function(objGrid,iIndex,objEvent) {
new Ext.menu.Menu({
items: [
Ext.getCmp('add').cloneConfig(),
Ext.getCmp('del').cloneConfig(),
Ext.getCmp('stop').cloneConfig()
]
}).showAt(objEvent.getXY())
}


The components I'm cloning configs from are similar buttons, from a toolbar

I've tried using return false, but that has no effect.. Do I need to add some other code or is it a bug?

karieanis
2 Aug 2009, 5:23 PM
Simple... stop the standard event before showing your context menu.

Like so:


rowcontextmenu: function(objGrid,iIndex,objEvent)
{
objEvent.stopEvent();

new Ext.menu.Menu({
items: [
Ext.getCmp('add').cloneConfig(),
Ext.getCmp('del').cloneConfig(),
Ext.getCmp('stop').cloneConfig()
]
}).showAt(objEvent.getXY());
}

mjlecomte
2 Aug 2009, 5:36 PM
Here's some code that might be useful:


listeners:{
rowcontextmenu: function(grid, rowIndex, e){
e.stopEvent(); // disable the standard browser context menu

//if we wanted access to the record, use:
var record = grid.getStore().getAt(rowIndex);

var sm = grid.getSelectionModel();

if (rowIndex === undefined) {
// if no row was selected from right clicking, clear the selections
sm.clearSelections();
}

if (! sm.isSelected(rowIndex)) {
sm.selectRow(rowIndex);
this.fireEvent('rowclick', this, rowIndex, e);
}

// create the context menu the first time
if(!grid.cmenu){
grid.cmenu = new Ext.menu.Menu({
items: [
{iconCls:'', text:'some text here'},
{iconCls:'', text:'another item'}
]
});
// ensure rendered so we can get height before showing menu below
grid.cmenu.render();
// make sure we clean up the menu
grid.on({
beforedestroy: function(grid){
// clean up the context menu
grid.cmenu.destroy();
}
});
}

var xy = e.getXY();
// to show the menu above the cursor
xy[1] -= grid.cmenu.el.getHeight();

grid.cmenu.showAt(xy);
}
},

karga
3 Aug 2009, 1:01 AM
It never ceases to amaze me how simple ExtJS is :P thanks