In my application, when the user clicks on a row, I reduce the size of the Grid to make room for a detail underneath, and use scrollToItem to ensure that the selected row is still visible.
The problem with this is that the row is always moved to the top of the grid, even when it would’ve been fine where it was.
This is jarring.
The behavior I’d like is to only “scroll” if needed to ensure the row is vertically inside the Grid, possibly with some margin.
I recall we used to have this feature in Vaadin 8, where you were able to give extra parameter, “scroll target” which defined whether the scroll is attempted so that the item will be at the top, bottom or somewhere in the middle, excluding the pathological cases where this cannot work. There is no replacement method in Grid currently unfortunately. The feature request is here: [grid] scrollToIndex(index) always scrolls so that the index is at top · Issue #1458 · vaadin/web-components · GitHub
I was afraid of that, but thanks anyway. In that case I won’t spend more time looking for a solution or workaround, and I’m certainly not going to wait for issues registered in 2019 and 2020…
For now I’ve restructured the code, so that I call “scrollToItem” in fewer cases, so that the problem is reduced at least.