Skip to content
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

Lazy expansion of TreeView nodes #135

Closed
timsneath opened this issue Jan 18, 2022 · 3 comments · Fixed by #139
Closed

Lazy expansion of TreeView nodes #135

timsneath opened this issue Jan 18, 2022 · 3 comments · Fixed by #139
Labels
enhancement New feature or request

Comments

@timsneath
Copy link

Firstly, this package is fantastic. What an incredible piece of work. So grateful for your work.

Scenario
I have a TreeView where it's computationally expensive to calculate the nodes. So what I want is a callback that I can use to lazily populate a node when it's opened. I've solved this temporarily by forking your code and adding an onExpanded callback. I've also added a non-visual PlaceholderTreeViewItem that ensures the node is expandable, and when the callback is fired, I check whether the child is a PlaceholderTreeViewItem. If so, I clear the children and populate at that point.

The solution I have is workable, but you may well have a better one.
https://github.com/timsneath/regedit/blob/main/lib/custom_tree_view_item.dart

Example usage:
https://github.com/timsneath/regedit/blob/main/lib/registry_tree_view.dart

@bdlukaa
Copy link
Owner

bdlukaa commented Jan 19, 2022

I have thought of only populating nodes when it's opened. That was the first implementation, but then I faced an issue: when I select an item, then close a parent node, the selected node is messed and its state is not kept.

I don't see a reason to add nodes only when it's opened. Could you explain more?

@timsneath
Copy link
Author

In the scenario above, I'm using it for a registry editor. There are hundreds of thousands of nodes in total, and so iterating them all in advance is not viable for performance reasons. This is quite a fairly common scenario for tree view controls, since they're often used as a control for very deep data sources (another example would be the folder structure of the C:\ drive).

Other TreeView controls handle this with the approach above or with a command. For example:
https://help.syncfusion.com/winui/treeview/load-on-demand
https://docs.microsoft.com/en-us/dotnet/desktop/wpf/controls/how-to-improve-the-performance-of-a-treeview?view=netframeworkdesktop-4.8
https://yui.github.io/yui2/docs/yui_2.9.0_full/examples/treeview/dynamic_tree.html

@bdlukaa
Copy link
Owner

bdlukaa commented Jan 20, 2022

Interesting. Marking as a valid request.

UI reference:

Loading GIF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants