PDA

View Full Version : Grid with contextmenu and rowcontextmenu



mschwartz
21 Aug 2009, 8:16 AM
I've set up a grid with both contextmenu and rowcontextmenu.

When I right click on the grid, the context menu works fine.

When I right click on a row, the row context menu works fine.

But when I pick an item from the row context menu, the desired action happens, but the grid's context menu then opens (afterwards).

Anyone else see this kind of behavior before?

(Both event handlers have e.stopEvent() as the first thing)

Condor
21 Aug 2009, 8:57 AM
That's normal.

You should check in your contextmenu event handler if you are not clicking on a row.

mschwartz
21 Aug 2009, 9:35 AM
That's normal.

You should check in your contextmenu event handler if you are not clicking on a row.

A code snippet would be nice.

Condor
21 Aug 2009, 10:14 PM
Here you go:

grid.on('contextmenu', function(e){
if(grid.getView().findRowIndex(e.getTarget()) === false){
// not clicked on a row
}
});

Animal
21 Aug 2009, 10:29 PM
The rowcontextmenu event of the GridPanel already does that for you.

But the OP's problam isn't that is it?

He's claiming the normal left click on an Ext.menu.Item triggers the browser's context menu?!??

"when I pick an item from the row context menu ... the grid's context menu then opens"

Condor
21 Aug 2009, 11:04 PM
BTW, GridPanel is still missing container events:

Ext.override(Ext.grid.GridPanel, {
processEvent : function(name, e){
this.fireEvent(name, e);
var t = e.getTarget();
var v = this.view;
var header = v.findHeaderIndex(t);
if(header !== false){
this.fireEvent('header' + name, this, header, e);
}else{
var row = v.findRowIndex(t);
var cell = v.findCellIndex(t);
if(row !== false){
this.fireEvent('row' + name, this, row, e);
if(cell !== false){
this.fireEvent('cell' + name, this, row, cell, e);
}
}else{
this.fireEvent('container' + name, this, e);
}
}
}
});

Animal
21 Aug 2009, 11:05 PM
That mod is in SVN

Condor
21 Aug 2009, 11:21 PM
That mod is in SVN

Ah yes, I hadn't looked through the SVN log for this week yet.

mschwartz
24 Aug 2009, 7:27 AM
The rowcontextmenu event of the GridPanel already does that for you.

But the OP's problam isn't that is it?

He's claiming the normal left click on an Ext.menu.Item triggers the browser's context menu?!??

"when I pick an item from the row context menu ... the grid's context menu then opens"

No.

If the grid is tall enough and it only shows a few records, there's room to right click on the grid below those records. We set up a context menu for that (below) and for rowcontextmenu.

When you right click on a row, the row context menu comes up. When you pick and item from that context menu, the action occurs and the grid's other context menu comes up.

Animal
24 Aug 2009, 7:34 AM
So your code is working as expected then.

Both context menus are shown. One above the other.

Condor
24 Aug 2009, 8:46 AM
Use the patch I posted above (also part of SVN) and attach the handler to the containercontextmenu instead of the contextmenu event.

mschwartz
24 Aug 2009, 12:11 PM
So your code is working as expected then.

Both context menus are shown. One above the other.

No, it isn't working as expected.

When you do:

e.stopEvent()

In the rowcontextmenu handler, it shouldn't pass the event to the other contextmenu event handler, should it?

It's not putting up both menus at once, it's putting up the rowcontextmenu, then when you click a menu item, the action for that menu item happens and then the grid's context menu comes up.

mschwartz
24 Aug 2009, 12:13 PM
Here you go:

grid.on('contextmenu', function(e){
if(grid.getView().findRowIndex(e.getTarget()) === false){
// not clicked on a row
}
});

This is what works.