How to get the current Grid Column when the GridContextMenu is opened

In our use-case we need the row (item) and Column for some actions we want to show in a context menu.

I cannot figure out how to get this information. Is this possible? If not, is this a planned feature?

Hi Ronald

You can get the item, but not the column. The getting of the item is relatively new (see [Jens Jansson’s post about it]
(https://stackoverflow.com/a/52356790/3441504) on stack overflow), and I personally would not count on being able to get the clicked column too in the near future. But I’m not in the official Vaadin team so don’t take my word for it!

// get the clicked item
GridContextMenu<FooBar> contextMenu = grid.addContextMenu();
contextMenu.addItem("action X", e -> {
	FooBar item = e.getItem();
});

Thanks Kaspar. Getting the item is clear for me (you referenced my own SO question :)).

This forum question is about getting the “current” Column.

I personally would not count on being able to get the clicked column too in the near future

Why? For me it seems very useful in many use-cases.

Oh that was your SO question :slight_smile: sorry

Because there is no issue about it on [github]
(https://github.com/vaadin/vaadin-grid-flow/issues?utf8=✓&q=is%3Aissue+is%3Aopen) (yet).

Feel free to open such an issue so they know that this need exists. If you do, it might be useful to also explain the reason why exactly you need to know what column was clicked. It will help them to better prioritize the issue, and maybe even provide you with a workaround.

Edit: And because this need has not arisen before, maybe this is a [XY problem]
(https://en.wikipedia.org/wiki/XY_problem) and what you want to do can actually be solved another way. Can you explain here why you need it?

I added some code that will extend the call to grid.addOpenedChangeListener(listener) so that the event listener code will be able to identify the row and column where the user right clicked. I hope Vaadin will include my contribution on version 13.
I’ll update this thread as soon as I get news on that.

That’s great Reuben! There is a pull request for your proposal?

https://github.com/vaadin/vaadin-grid-flow/pull/504

@Reuben. Have you see this? https://vaadin.com/releases/vaadin-13#grid-event-context

Interesting, this might be exactly what I was looking for.
In any case my pull request was approved…

Hi Ronald,
I updated to vaadin-flow 13.0.1 (which includes vaadin-grid-flow 3.0.3), and there is no method getEventContext as documented in the link above (https://vaadin.com/releases/vaadin-13#grid-event-context).

Hi Reuben,

I hope Vaadin will include my contribution on version 13. I’ll update this thread as soon as I get news on that.

In any case my pull request was approved…

Just checked out 13.0.4, but your code is not available (yet). Is this correct or do i miss something?

Hello. I also want to get mouse right-click events on the grid. It is for select row that has been right-clicked.
And it will be fine if we can generate grid’s context menu items depends on clicked row/column.