Guttorm
(Guttorm Vik)
1
I need to know which column was right-clicked to build the grid context menu.
Checking the source, I see the dynamicContentHandler is invoked from GridContextMenu.onBeforeOpenMenu(JsonObject eventDetail)
Setting a breakpoint in that eventDetail looks like this:
{“key”:“3”,“columnId”:“”}
So, column, but not
virkki
(Tomi Virkki)
2
Guttorm
(Guttorm Vik)
3
Thanks.
Registered in 2020, flagged as an enhancment and still open 
The linked duplicate #424 suggests a workaround; Subclass Grid and use a modified gridConnector.ts. That sounds possible, but not fun.
Guttorm
(Guttorm Vik)
4
The linked issue #1939 had a much simpler workaround suggested by @Tatu2:
String expression = "function(){const col=element.getEventContext(event).column;return col ? col.id : '';}()";
getElement().addEventListener("contextmenu", event -> {
String colId = event .getEventData().getString(expression);
Optional<Column<Bean>> column = getColumns().stream().filter(col -> colId.equals(col.getId().get())).findFirst();
System.out.println("setting domevent column id: " + column.get().getId().get());
domEventColumn = column.get();
}).addEventData(expression);
It didn’t work out of the box, but if I also give all my columns an id, with column.setId(xx), then it works. Maybe Vaadin set id earlier?
Since we probably want IDs anyway for testing, that is an acceptable solution.