Scroll to a row in Grid?

Is the scrollToRow method missing in V10 (Flow) Vaadin? Is there any other alternative?

This feature has not been implemented yet, there is feature request here

https://github.com/vaadin/vaadin-grid-flow/issues/289

(Note: the example there is written in Kotlin, not Java)

The workaround is to peform JavaScript call via UI.getCurrent().getPage().executeJavaScript(“$0._scrollToIndex($index)”, element)

Hi Tatu,

Thank you very much indeed!

Should anybody need, here is my code that works fine:

class MyGrid extends Grid {
   
   ...

       setItems(content);

   ...

   private void scrollToBottom() {
     UI.getCurrent().getPage().executeJavaScript(
             "$0._scrollToIndex($1)",
             FileGrid.this, content.size() - 1);
   }

The workaround does work, in that it scrolls to the given index in the displayed table. If I have a filter or sort order set on the grid, how can I get the correct index to scroll to?

In generic case scrollToItem() is more complex since you need to have item to row index translate function. This is missing feature in DataProvider, I have commented it here (its Vaadin 8, but DataProvider is somewhat indentical there)

https://github.com/vaadin/framework/issues/9266#issuecomment-455287292

In Vaadin 8 you could it with this kind of workaround

https://github.com/vaadin/framework/issues/10935

(which can be very expensive with lazy data providers, which is the reason why I am proposing a better solution in https://github.com/vaadin/framework/issues/9266)

The same is not possible with Flow due https://github.com/vaadin/flow/issues/4510

Naturally if you happen to have ListDataProvider and no filtering and sorting, you do not need the above mentioned function and getting index is trivial.

Hello!

Are there some news about the missing method “scrollToRow” for Vaadin 14.x?

I need this method, too.

With kind regards
Thomas

Are there some news about the missing method “scrollToRow” for Vaadin 14.x?

Grid has scrollTo method introduced in Vaadin 14.1.

Thanks for the “scrollToRow” method.

But for DataProvider with lazy loading, filtering and sorting finding out the row gets tricky.

Could you suggest an approach for a “scrollToItem” method under those circumstances?

Something like this https://github.com/vaadin/vaadin-grid-flow/issues/327#issuecomment-502698478

Greetings