Tatu2
(Tatu Lund)
October 14, 2024, 4:34am
5
It may be the same bug as described here. Scrolling to index does not happen before Grid rendering is complete. And doing refreshAll will retrigger Grid render.
opened 09:47AM - 11 Oct 24 UTC
bug
workaround
### Description
If I set both the items in the afterNavigation and then immed… iately scroll to index, Grid is not scrolling. There is apparently some glitch with timing. Possibly Grid rows are not rendered yet when scroll is attempted. This is very likely scenario as Grid data is often fetched from backend and set in afterNavigation, furthermore target item can be url parameter.
### Expected outcome
Grid should have been scrolled to target index.
### Minimal reproducible example
```
@Route(value = "grid-scroll", layout = MainLayout.class)
public class GridScrollIssue extends VerticalLayout
implements AfterNavigationObserver {
Grid<String> grid;
public GridScrollIssue() {
grid = new Grid<>();
grid.addColumn(item -> item).setHeader("Item");
var button = new Button("Scroll", e -> grid.scrollToIndex(200));
add(grid, button);
}
@Override
public void afterNavigation(AfterNavigationEvent event) {
grid.setItems(IntStream.range(0, 1000).mapToObj(i -> "Item " + i)
.collect(Collectors.toList()));
grid.scrollToIndex(200);
}
}
```
### Steps to reproduce
Navigate to view and observe that Grid is not scrolled. Clicking the button will scroll the Grid to right row.
### Environment
Vaadin version(s): 24.4.12
### Browsers
_No response_