-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TreeGrid scrollToIndex problem on large tree with expanded nodes #1016
Comments
After investigating this we concluded that the current API of
In order for the original use-case to work we would need to introduce a new feature and new API. There are several existing ideas that could be explored:
We also need to deal with the existing
|
Of the options for the existing scrollToIndex API, I think the preferrable option would be to redefine it to work only with root nodes, as that is still a useful feature in cases where scrolling to nested nodes isn't necessary. This would need to be reflected in javadoc and documentation. A new API/feature would need a separate enhancement ticket, and presumably some more investigation to assess the feasibility and solution details. |
To be able to scroll to a specific index, even if it's lazy-loaded multi-level we flatten out and determine the index on the server side. This is some sort of workaround. The new propsed API here would be much better. But it somehow works (given that we also expand the items to the level, and try to scroll per js afterwards again which is not very smart). Since redefining the purpose of the method would break existing code I tend to vote for deprecation/removal. Also I have problems understanding why the tree does not know how to scroll to the index: The tree knows its expanded nodes and if a user manually scrolls to a specific position the tree must also show the correct subview. Since scrollPx / cellHeight = index (in a simple tree with identical cell heights) that looks very similar to the scrollToIndex method. But I'm of course ok with the proposal. Just my 2 cents. |
@INPUTsys-Chris
On the client-side the tree grid uses lazy-loading which means it does not know about the whole structure of the tree, it knows only about the parts that were scrolled into view at some point. So while it knows which nodes are expanded it does not know how many child nodes an expanded node has unless the loading for that sub-tree happens. As such it can not calculate an effective scroll index since it doesn't know how many nodes in the flattened hierarchy need to be skipped, or even how long the effective hierarchy is. Consider the following (simplified) example. In the example the grid can only show 5 items at once, which means it will only load the first five root items of the tree. Then we issue a command to expand node 7 - that has no effect so far, as node 7 is not loaded yet. Now we want to scroll to node 7-5 which should have the effective index 12. However the grid does not know yet that node 7 has 5 children, which would affect the effective length of the hierarchy. Instead it will skip right over node 7 and its children and scroll to node 12.
Maybe the confusion also comes from comparing this to manual scrolling. When scrolling manually the scroll position is changed incrementally, which gives the grid time to catch up with loading further parts of the tree. When scrolling programmatically that happens instantaneously, there is no opportunity for the grid to load the missing nodes in between. Anyway, hope that clears it up a bit 🙂 |
Thanks for your detailed description. I understand the explanation but the scrollbar of the tree indicates the tree does know the size including expanded nodes. If your explanation would be true, the scrollbar thumb would be changing height by scrolling. I've never seen that. And this is also the reason I beleive it should work: The destination scroll pos is reachable. The only problem we face is that it takes time to expand the nodes and that's a timing issue IMHO. I'm talking about Java API only, so maybe the pure JS tree grid may have these problems. |
Maybe you haven't had any obvious examples, but it will definitely do that. The scrollbar will only update when expanding nodes, if those nodes are part of the visible area (note the grid fetches some additional nodes around the visible area to prevent empty content when scrolling). |
@INPUTsys-Chris yes, it is more a problem on the JS side, because of timing (waiting for expanded nodes to be rendered within the DOM - otherwise the correct node is not reachable) I did a workaround by determining all subnodes within the path from a root node to the node to scroll to. And then scroll to the root/subnodes recursivly (and expand them), an event is fired (on the JS side, if the tree-side changes - done by a mutation observer (height changed) - then do the ScrollTo(index). This approach basicaly works in many cases. But it fails, if the Cache is not filled (which will work, if I scroll manually - the cache will be filled and scrollTo(index) will succed. I don't know how the cache is filled in the treeGrid, but I think, this is not done correctly, because of the lazy loading mechanism. Unfortunatly there is no parameter for the (tree)grid to set the amount of nodes to be rendered. |
@sissbruecker |
@Rob-Rocket we did similar and it works for us, too. But of course a new stable API without workarounds would be great. Good to have your workaround (which is better than ours) documented here in case someone else has problems until the new API is here. Thanks |
Due to the difficulties encountered when using the A new issue was opened to eventually provide an implementation with predictable behavior. |
Just pointing earlier comment #1016 (comment)
This has been effectively done now: #2648 |
Description
TreeGrid scrollToIndex is not working properly on a large tree with expanded nodes.
Steps to reproduce
In a 14.4.10 project, add the following to a view and click on the button
Expected outcome
The tree expands and the scrolls to index 500
Actual outcome
The tree expands, but no scrolling occurs.
A second button click is required to scroll to the index. Notice, also that workaround of calling
UI.getCurrent().beforeClientResponse(grid, ctx -> grid.scrollToIndex(500));
(which works in the case of shallow trees) doesn't seem to work with large trees with expanded nodes.The text was updated successfully, but these errors were encountered: