Grid. Select first row per default

Hello,

how can i select first row per default after the data was loaded.

i use DataProvider with lazy loading.

thx.

Vaadin Flow Grid has method Grid.select(item), which selects item programmatically. So you need to resolve the item. The best way to get it, is to use Grid.getDataCommunicator() which has the following method, fetchFromProvider:

https://demo.vaadin.com/javadoc/com.vaadin/vaadin-core/10.0.2/com/vaadin/flow/data/provider/DataCommunicator.html#fetchFromProvider-int-int-

So fetchFromProvider(1,1) returns a stream of one item you want to select.

Tatu Lund:
Vaadin Flow Grid has method Grid.select(item), which selects item programmatically. So you need to resolve the item. The best way to get it, is to use Grid.getDataCommunicator() which has the following method, fetchFromProvider:

https://demo.vaadin.com/javadoc/com.vaadin/vaadin-core/10.0.2/com/vaadin/flow/data/provider/DataCommunicator.html#fetchFromProvider-int-int-

So fetchFromProvider(1,1) returns a stream of one item you want to select.

thanks, bu this method is protected, i can not do this grid.getDataCommunicator().fetchFromProvider(1,1);

can you give me a full example please?

That is a good finding, which I did not noticed by quick glance, since the equivalent method in Vaadin 8 used to be public. I created a request for change about it:

https://github.com/vaadin/flow/issues/4510

Tatu Lund:
That is a good finding, which I did not noticed by quick glance, since the equivalent method in Vaadin 8 used to be public. I created a request for change about it:

https://github.com/vaadin/flow/issues/4510

ok, thank’s, thats means, that we doesn’t have any solution or workaround for my issue?

Alternative approach would be to use DataProvider.fetch(…) method

https://vaadin.com/api/platform/10.0.3/com/vaadin/flow/data/provider/DataProvider.html#fetch-com.vaadin.flow.data.provider.Query-

But in trivial case (ListDataProvider) you can get the first item of the list underneath the data provider.

Are there any news about how to select the first row when using a CallbackDataProvider?

Note there is a lot of discussion about https://github.com/vaadin/flow/issues/4510. The change is not available as of Q1 2020. Also note we have an efficiency problem with the current design of the data provider. Because there is no API for getting the current content of a Grid, you are forced to query the data again and must be sure to fire the exact same query, which could be out-of-sync!

So to recap. In non-trivial/lazy load Grids (not using ListDataProvider) you are forced to query the data again, which is

  • inefficient
  • cumbersome
  • not robust

So the best solution imho is to cache the last query (or a subset, dependent on your use-case) by the DataProvider.

Hope to have the github issue designed soon !