Grid how to select the first row. Vaadin 8

I need to to select from the program the first row of a grid.
I can I get the ID of such row ?
I didn’t find the way.
Tks

Yes, select(…) method takes item as parameter, not row index. You can find the row index via DataCommunicator

item = grid.getDataCommunicator().fetchItemsWithRange(0,1).get(0);


https://vaadin.com/download/release/8.3/8.3.1/docs/api/com/vaadin/data/provider/DataCommunicator.html#fetchItemsWithRange-int-int-

I see two problems in your solution :

  • in 8.1 the method is protected
  • the method seems to reexecute the query and I don’t want to do it, I just need to have the first item in order to select it.

Tks
Tullio

in 8.1 the method is protected

It is opened in 8.2+

the method seems to reexecute the query

If you can assume using ListDataProvider (the default for Grid) and not using sorting and filtering, then grid.getDataProvider().getItems().get(0) works for you.

Tks but I don’t use ListDataProvider and I can use both filtering and sorting.
Tks