vaadin / flow-components

Java counterpart of Vaadin Web Components
100 stars 66 forks source link

GridContextMenu dynamicContentHandler called before _contextMenuTargetColumnId is set by Grid.updateContextMenuTargetItem #2258

Open kovadam69 opened 3 years ago

kovadam69 commented 3 years ago

Description

In Grid there is a method updateContextMenuTargetItem which updates the key and column Id from client side using properties. However this method is called and thus column ID is populated after the attached GridContextMenu's dynamicContentHandler has been called. Therefore it is impossible to build a context menu which related to a specific column in the Grid. This is especially necessary for Grid Header related Context Menus (like sorting, filtering, data ordering, etc.).

Expected outcome

I expect the clicked column ID to be populated before the dynamicContentHandler will be called, so assembling a Context Menu can relay on column ID information.

Actual outcome

Currently I have to click the column twice, because the first click has either no column id (empty string at first click ever) or the previously clicked column's ID.

Steps to reproduce

  1. Create a grid with data and some columns, set ID for each column (like. column.setId("col1");)
  2. Attach a context menu with a dynamic content handler
  3. Put this line in the context handler: String columnId = .getElement().getProperty("_contextMenuTargetColumnId"); -> write columnId to log or system out
  4. Click around in the table, and check the columnId the first click ever will be empty string, every other click will show the previous clicked column
  5. Using debugger set a breakpoint on the dynamicContentHandler and on the Grid.updateContextMenuTargetItem method. You will notice, the dynamicContentHandler will be called before the updateContextMenuTargetItem.

Environment

yuriy-fix commented 3 years ago

Could be related: https://github.com/vaadin/flow-components/issues/1939

kovadam69 commented 3 years ago

Well it's a similar problem, but actually the data is there, just not before the dynamiccontenthandler is called... I think it would be enough to somehow switch the orders how the data population from the client side is handled, and populate the clicked column id before the dynamic context menu callback has been called... it would be a nice add-on to have the clicked columnid in the event, but not necessary, it can be accessed using getElement().getProperty()...