Grid: Get row number of item

In Grid:

With a given item (my bean) - how can I get the number of the row, in which this item is displayed?

Hi,

Since Framework version 8.4.0 ([release notes]
(https://github.com/vaadin/framework/releases/tag/8.4.0)) the Grid.ItemClick<T> event ([Grid.ItemClick doc]
(https://vaadin.com/api/com/vaadin/ui/Grid.ItemClick.html)) also contains the row index information of the clicked item, but I don’t think there is a way to get the row index of a bean without that.

-Katri

before that we had a ugly workaround :frowning:

we hat

private List<Item> items;
private Grid<Item> grid;

as a Class Fields.

in the initialisation method we filled the List with items and had

grid.setITems(items);

onclick we allways had the item from click Event
earlier something ugly like (Item) event.getSource().getValue() i think with modern Vaadin the Event is parametrised, so we simply get event.getValue()

then we used items.indexOF(event .. get Value ..);

so i am VERY thankfull, that since Vaadin 8.4 we can refactor this :slight_smile: ! ! !