Grid scrollToEnd() after setItems()

Hello vaadiners

I have a vaadin grid where I call setItems(). There are more rows than fit on my screen. I want the grid to scrollToEnd() AFTER all the rows have been added.

  • I tried calling scrollToEnd() right after the setItems() method
  • I tried calling scrollToEnd() inside of my addComponentColumn lambda
  • I tried using the return value of setItems() and added a addItemCountChangeListener to call the scrollToEnd(). This listener was run after all columns have been added, but the grid wasn’t scrolled to end.

However the grid never appeared on my webbrowser scrolled to the end.

I then added a Button on the view to call scrollToEnd() after click. This worked.
Is there a way to have the grid automatically scrolled to the bottom after I’ve set all my items with setItems() ?

This looks related: https://github.com/vaadin/flow-components/issues/4497

There was a PR with a suggested fix which you could try as a workaround:


getUI().orElseGet(UI::getCurrent).beforeClientResponse(this,
                ctx -> grid.getElement().executeJs(
                        "const el=this; setTimeout(()=>el.scrollToIndex(el._effectiveSize),0);"));