vaadin / flow-components

Java counterpart of Vaadin Web Components
82 stars 63 forks source link

Pb method scrolltoindex in “beforeEnter” method #6336

Open jcaSteelElec opened 1 month ago

jcaSteelElec commented 1 month ago

Description

I want to scroll my grid to the last position after comeback from another screen. I use the grid function "scrolltoindex(int i)" in the “beforeEnter” method in my view but it doesn’t work, my grid begin always at the first row. I haven’t problem if I use the scrolltoindex method on click on a button for example. In "beforeEnter()" or "AfterNavigation()", It's not possible to use it. In Vaadin forum, Tomi help me with a workaround solution : grid.getElement().executeJs("setTimeout(() => this.scrollToIndex(20))");. And that work fine in those method.

Expected outcome

I would except that the method scroll at the indice I want in "beforeEnter()" method.

Minimal reproducible example

@Override
public void afterNavigation(AfterNavigationEvent event) {       
            myGrid.scrollToIndex(index);

}

Steps to reproduce

Use two view: view A and view B. In the view A add a grid and load it with several row. In that view, use @SpringComponent and @UIScope to save the IHM after leaving the view. Add a button to go to view B. Open view A: the grid is loaded. Click on button and go to view B. Then quit view B to display the view A. The grid in view A shoud have scrolled at the indice.

Environment

Vaadin version(s): 24.3.5 OS: Windows 11

Browsers

Chrome