PDA

View Full Version : groupcontextmenu stop group toggling



LambyPie
3 Feb 2010, 9:11 AM
I am using a GridPanel with a GroupingView and when the user clicks a group header row I want to display a context menu with options to expand all and collapse all groups. I am successfully using the new 'groupcontextmenu' event to do this and its working well. The only problem is that when the user right clicks the group header it expands/collapses the group before showing the context menu (as if they had left clicked the group header). I can't find an event or a way to stop this happening - any help?

There is the 'groupmousedown' event which looks like it would do the job but doesn't appear to get fired?

csky
11 May 2010, 7:24 PM
Having the same problem here. Were you ever able to figure this out?

LambyPie
12 May 2010, 12:29 AM
I did figure out a workaround (I am using ExtJS 3.1.1), I am subclassing the GridPanel, here is my stripped down code:



Boe.GridPanel = Ext.extend(Ext.grid.EditorGridPanel,
{
initComponent:function()
{
....

// add an interceptor to the GroupingView interceptMouse method
// NB What this does is stop the grouping view from toggling the
// group on a right mouse click. This is required because we are
// throwing up a context menu (see "groupcontextmenu" listener
// below) and we don't want the group to toggle when the
// context menu is displayed
this.view.interceptMouse = this.view.interceptMouse.createInterceptor(
function(e)
{
// stop the call when it is the right mouse button
return e.button!=2;
});

this.on('groupcontextmenu', function(grid, grpFld, grpVal, e)
{
// suppress default browser menu
e.preventDefault();

// show default context menu
var cmnu = new Ext.menu.Menu();
cmnu.add({text:'Expand all',scope:this,handler:function(){this.getView().expandAllGroups();}});
cmnu.add({text:'Collapse all',scope:this,handler:function(){this.getView().collapseAllGroups();}});
cmnu.showAt(e.xy);
});

// add groupchange handler to workaround ExtJs bug when groups are removed and then added again
this.on('groupchange', function(view,fld)
{
// this turns off the hideGroupedColumn setting when no grouping is selected then
// turns it back on when a new group is selected. Without this ExtJs throws an error
// when grouping is turned back on after being turned off
view.hideGroupedColumn=(fld!=null);
});

....
}
});


However, also see this thread about fixing the groupmousedown event:

http://www.extjs.com/forum/showthread.php?92852-FIXED-652-groupmousedown-event-doesn-t-fire&p=440525#post440525

I haven't tried this but it might be "cleaner" to listen on groupmousedown and then stop the event for a right click that way.