PDA

View Full Version : right click on a grid



cliclem
25 May 2010, 12:31 AM
Hello, I want to handle a right click on a grid: how can I do ?

I tryed to use "Events.CellMouseUp" but the context Menu appears when right click.

So the only bad solution I founded is to disable the context menu on root panel :/ I would like to do it just on the grid, but it doesnt't work. How can I do ?.

public static native void disableContextMenu(Element e) /*-{
e.oncontextmenu = function() { return false; };
}-*/;

Thanks for your help

sven
25 May 2010, 12:52 AM
Add an Events.OnContextMenu listener to the grid and prevent the default action.

cliclem
25 May 2010, 1:42 AM
I tried this: It execute OnMouseUp action well, but it doesn't execute OnContextMenu. I also tried ContextMenu.

grid.addListener (Events.OnContextMenu, new Listener<BaseEvent>() {
@Override
public void handleEvent (BaseEvent be) {
be.setCancelled (true);
}
});

grid.addListener (Events.OnMouseUp, new Listener<GridEvent<Projet>>() {
@Override
public void handleEvent (GridEvent<Projet> s) {
if (s.isRightClick ()) {
final CellSelectionModel<Projet> selectionModel = (CellSelectionModel<Projet>) grid.getSelectionModel ();
selectionModel.selectCell (s.getRowIndex (), s.getColIndex ());
s.getGrid ().fireEvent (Events.CellClick, s);
}
}
});

sven
25 May 2010, 1:50 AM
also sink the event.

cliclem
25 May 2010, 1:56 AM
thanks a lot, it works !!

souihli
29 Jun 2010, 1:09 AM
It doesnt work for me :(
Can someone explaine me how to "sink the event" ?!
Thanks in advance :)

mwmcmullen
30 Jun 2010, 2:35 AM
Mine doesn't seem to work as well.

I have:




registryGrid.addListener(Events.OnContextMenu, new Listener<GridEvent<MyModel>>()
{
@Override
public void handleEvent(GridEvent<MyModel> be)
{
if(be.isRightClick())
{
Info.display("YES!!", "isRightClick()");
com.google.gwt.user.client.Window.alert("Works!!");
}

}
});



Also, may I ask for the reason why the Events.OnContextMenu is called this? It doesn't seem all that logical? Before I seen this thread, I was trying 'OnClick' and testing if it was a 'right click'. Or am I misunderstanding something?

mwmcmullen
30 Jun 2010, 3:55 AM
Doesn't appear to work for me either.


Ability to 'right-click' on a row in the grid for menu options to appear





Grid<MyModel> myGrid = new Grid<MyModel>(myStore, createColumnModel());
myGrid.setTitle("Datum Registry");
myGrid.setBorders(false);
myGrid.setPixelSize(600, 270);

myGrid.addListener(Events.OnClick, new Listener<GridEvent<MyModel>>()
{
@Override
public void handleEvent(GridEvent<MyModel> be)
{
if(be.isRightClick())
{
Info.display("Information", "You have just right clicked");
}
}
});



May I also ask why you're using 'OnContextMenu' as the Event in the listener? Surely it would be an OnClick as this is the event you are listening for essentially?

sven
30 Jun 2010, 4:10 AM
You have to listen to OnContextMenu for a right click.

You are not sinking the event. This is basic GWT stuff.

grid.sinkEvents(Event.ONCONTEXTMENU);

souihli
30 Jun 2010, 4:11 AM
Hi mwmcmullen (http://www.sencha.com/forum/member.php?112941-mwmcmullen) !
It still doesn't work for me with this code. But i solved my problem ;)
In fact i needed to show a menu on right click on a cell grid.
So i just had to make :
"grid.setContextMenu(myMenu);"
Adding a contextMenu to a grid, removes automatically the browser context menu. So my problem is solved ! No need to add listeners !! (yoooooopii !)
Hope this will help you !

mike b
2 Dec 2010, 1:51 PM
GXT 2.2.1 / GWT 2.1.0

I'm not sure if my goal was the same as everyone else's, but I was trying to disable all default Right Click functionality on the Grid, so that i could display a ContextMenu with out any row specific context.

These 2 things worked for me:

1) override the handleMouseDown method of CheckBoxSelectionModel. I had used the sample code from here: http://www.sencha.com/examples/explorer.html#checkgrouping


@Override
protected void handleMouseDown(GridEvent<FunkyTown> e) {
if (e.getEvent().getButton() == Event.BUTTON_RIGHT ) {
//ignore
GWT.log("ignoring Mouse Down");
} else {
super.handleMouseDown(e);
}
}2) override the onMouseDown in the GridView (also sample code, see above link)


@Override
protected void onMouseDown(GridEvent<ModelData> ge) {
if( ge.getEvent().getButton() == Event.BUTTON_RIGHT ) {
//ignore
GWT.log("ignoring Mouse Down");
} else {I did not need to add listeners or sink events. Of course, I did have to add my Menu to the Grid with the setContextMenu method


this.grid.setContextMenu(menuRightClick);

Bear_On_Fire
12 Jun 2014, 4:28 AM
Hi mwmcmullen (http://www.sencha.com/forum/member.php?112941-mwmcmullen) !
So i just had to make :
"grid.setContextMenu(myMenu);"
Adding a contextMenu to a grid, removes automatically the browser context menu. So my problem is solved !
THANK YOU SO MUCH =D>