Open enver-haase opened 6 months ago
I think you use wrong scrollToIndex method in the code, see: https://vaadin.com/docs/next/components/tree-grid#programmatic-scrolling
That has to do with the fact that I cannot see any method that would return such an array of int, in order to parametrize scrollToIndex(int...)
.
Unfortunately you need to figure out the indexes yourself based on the data you feed into the TreeGrid. Ideally, you would instead use scrollToItem, but that doesn't work in TreeGrid. These are known issues for which we have not been able to find a solution yet.
In many cases, a scrollToSelected()
with no parameters would be good enough. Has that been considered?
In my experiments, I could see that dataCommunicator.getParentItem(T item)
is unreliable (works only when the item's parent is expanded). That's not documented and needs to be repaired.
In case the TreeGrid has a TreeData, that data structure's getParent can be used instead. It can also be used to find the int[] needed for scrollToIndex(int...) like so:
parent = getTreeData().getParent(current); // this can be considered back-end access
int index = getTreeData().getChildren(parent).indexOf(current);
indices.add(index);
in a loop from item to root, then reverse the indices list and do
int[] in = indices.reversed().stream().mapToInt(Integer::intValue).toArray();
scrollToIndex(in);
in the same loop, the parental chain can also be recorded and later be used for node-by-node expansion.
Description of the bug
I should be able to scroll any item into view, and also expand the parent nodes. But even the calculation of the parent node(s) does not work reliably.
Expected behavior
I'd like to have a simple 'expandRouteToItemAndScrollIntoView(T item)'. I'd like the existing API to function as expected.
Minimal reproducible example
Versions