Context menu box in a Table

Hi there,

I have studied the sample of table styling. So I can

  • right click on a record to select that record
  • right click on a record to open a context menu

However when I combine these two, the context menu just shows up (for half second) and disappears right away, the record is selected still. Here is my code. My use case is: right click on a record in a table, the record is highlight(selected), the context menu box is shown.


tblResult.setImmediate(true);
tblResult.setMultiSelect(false);
tblResult.setSelectable(true);

tblResult.addListener(new ItemClickListener() {
	public void itemClick(ItemClickEvent event) {
		if (event.getButton()==ItemClickEvent.BUTTON_RIGHT) {
			tblResult.select(event.getItemId());
		}
	}
});

tblResult.addActionHandler(new Action.Handler() {
   public Action[] getActions(Object target, Object sender) {
      // prepare menu box based on conditions.
   }

   public void handleAction(Action action, Object sender, Object target) {
      Item rowItem = tblResult.getItem(target);
      // take action
   }
});

Does any one face the same problem? It is like in a windows file browser, you can right click on a file, the file get selected and a context menu is shown. Thanks!

-Xuan

Sounds to me like a bug, you should be able to do that. I guess no one has tried this before, so you were the unlucky one to discover it. Could you create a ticket and a test case for us, so we can fix it (
issue tracker
)? Thanks!

I would like to achieve the same behaviour on right-click in tables.

It is the behaviour in most applications to
act on trigger-button (right) in a table, list or tree, by selecting the
item and showing the context menu.
Unfortunately the Vaadin Table only shows the context menu
without selecting the item (row).

Is it possible to get the Table widget (and others) to behave
like that?

If not, can anyone propose a workaround?

/Tomas

Was an issue ever filed for this? I’m happy to file one to add an option to Table so that right-clicking a row selects it or at least creates some visual marker so that users know upon which row the action will operate.

Related: is there any visual difference already that I’m not seeing, for instance something I could make more obvious through CSS? For instance, when right-clicking on something in a MacOS Finder list, it leaves the originally-selected item selected, but the right-clicked item is highlighted so you at least know what’s happening.

Thanks,
Bobby

Answering my question about an issue, I found
this one
.

Was this ever fixed? I’d like to be able to have the context menu select also make the same row selected.

This bug was opened 4 years ago. Any chance of a fix, or if you don’t want to change current behaviour at least give us a way to do a select on the context menu row.

Thanks.

Hi,

I know probably it’s a bit late, but if your sole problem is that you want the row in the table to be selected when you right-click on an item in your Table (mine is a TreeTable but it should work the same way), you can do it by yourself adding a ContextClickListener (I don’t know if that was available 7 years ago), and I don’t think at all that ContextMenu should do it automatically. Why? Why if I don’t want the clicked row to be selected, @Dino Fancellu?

For instance:

myTree = new Tree("My tree"); myTree.setSelectable(true); // your tree needs also to be selectable; maybe you are missing this one? myTree.addContextClickListener(new ContextClickListener(){ @Override public void contextClick(ContextClickEvent event) { TableContextClickEvent tce = (TableContextClickEvent)event; Object itemId = tce.getItemId(); myTree.select(itemId); } Then in your ContextMenu you simply add your item as usual and if you want the id of the clicked item, you do it as usuarl with a

myTree.getValue(); and as the row is selected it will pick up the proper value.

I don’t know if I’m missing some important key here but that’s how I do it and looks rather easy to me…