From 9c88b10dc53ae4d708522a06e4cbb705920a8d74 Mon Sep 17 00:00:00 2001 From: 10x developer <57017344+ddjerqq@users.noreply.github.com> Date: Tue, 22 Oct 2024 14:25:30 +0400 Subject: [PATCH] TreeView: Add virtualization support (#5689) * added virtualization support to treeview * Replaced a regular html anchor tag with a blazorise Anchor component. Added the relevant logs to the current changelog's optimization section. Updated the summary string documentation for the Virtualize Parameter of TreeView * formating * Mention default value * Fix virtualization * Add Virtualization example * Don't pass styling parameters further from root element * Use defaults when Virtualize is enabled * release notes * Change description * Docs notes * testing treeview virtualize with dynamic data * Properly fallback to default Height and Overflow values * Remove extra parenthesis * Fix duplicate nodes --------- Co-authored-by: ddjerqq <570173344+ddjerqq@users.noreply.github.com> Co-authored-by: Mladen Macanovic Co-authored-by: Mladen Macanovic Co-authored-by: David Moreira --- .../Pages/Tests/TreeViewPage.razor | 5 + .../Pages/Tests/TreeViewPage.razor.cs | 29 +- .../Models/Snippets.generated.cs | 40 +++ .../TreeViewVirtualizationExampleCode.html | 44 +++ .../TreeViewVirtualizationExample.razor | 41 +++ .../Extensions/TreeView/TreeViewPage.razor | 33 ++ .../News/2024-10-15-release-notes-170.razor | 8 + .../Internal/_TreeViewNode.razor | 121 ++++--- .../Internal/_TreeViewNode.razor.cs | 13 +- .../Blazorise.TreeView/TreeView.razor | 27 +- .../Blazorise.TreeView/TreeView.razor.cs | 27 ++ workload-install.ps1 | 328 ++++++++++++++++++ 12 files changed, 630 insertions(+), 86 deletions(-) create mode 100644 Documentation/Blazorise.Docs/Pages/Docs/Extensions/TreeView/Code/TreeViewVirtualizationExampleCode.html create mode 100644 Documentation/Blazorise.Docs/Pages/Docs/Extensions/TreeView/Examples/TreeViewVirtualizationExample.razor create mode 100644 workload-install.ps1 diff --git a/Demos/Blazorise.Demo/Pages/Tests/TreeViewPage.razor b/Demos/Blazorise.Demo/Pages/Tests/TreeViewPage.razor index 43b1d977fa..2c9dd92f30 100644 --- a/Demos/Blazorise.Demo/Pages/Tests/TreeViewPage.razor +++ b/Demos/Blazorise.Demo/Pages/Tests/TreeViewPage.razor @@ -26,6 +26,7 @@ + @@ -41,12 +42,16 @@ } + + Virtualize + treeViewRef; - private IList expandedNodes = new List(); - private IList selectedNodes = new List(); + private IList expandedNodes = new ObservableCollection(); + private IList selectedNodes = new ObservableCollection(); private NodeInfo selectedNode; private TreeViewSelectionMode selectionMode; + private bool virtualize; public class NodeInfo { public string Text { get; set; } - public IEnumerable Children { get; set; } + public ObservableCollection Children { get; set; } public bool Disabled { get; set; } } - private IEnumerable Nodes = new[] + private ObservableCollection Nodes = new ObservableCollection() { new NodeInfo { Text = "NodeInfo 1" }, new NodeInfo { Text = "NodeInfo 2", - Children = new [] + Children = new ObservableCollection() { new NodeInfo { Text = "NodeInfo 2.1" }, new NodeInfo { - Text = "NodeInfo 2.2", Children = new [] + Text = "NodeInfo 2.2", Children = new ObservableCollection() { new NodeInfo { Text = "NodeInfo 2.2.1" }, new NodeInfo { Text = "NodeInfo 2.2.2" }, @@ -51,12 +53,12 @@ public class NodeInfo new NodeInfo { Text = "NodeInfo 4", - Children = new [] + Children = new ObservableCollection() { new NodeInfo { Text = "NodeInfo 4.1" }, new NodeInfo { - Text = "NodeInfo 4.2", Children = new [] + Text = "NodeInfo 4.2", Children = new ObservableCollection() { new NodeInfo { Text = "NodeInfo 4.2.1" }, new NodeInfo { Text = "NodeInfo 4.2.2" }, @@ -72,6 +74,17 @@ public class NodeInfo new NodeInfo { Text = "NodeInfo 6" } }; + + int count = 0; + private async Task AddNode() + { + count++; + selectedNode.Children ??= new ObservableCollection(); + selectedNode.Children.Add( new NodeInfo() + { + Text = selectedNode.Text + count, + } ); + } private async Task ForceReload() { await treeViewRef.Reload(); diff --git a/Documentation/Blazorise.Docs/Models/Snippets.generated.cs b/Documentation/Blazorise.Docs/Models/Snippets.generated.cs index 9ae12ca787..55774017ac 100644 --- a/Documentation/Blazorise.Docs/Models/Snippets.generated.cs +++ b/Documentation/Blazorise.Docs/Models/Snippets.generated.cs @@ -10970,6 +10970,46 @@ public class Item public const string TreeViewResourcesExample = @""; + public const string TreeViewVirtualizationExample = @" item.Children)"" + HasChildNodes=""@(item => item.Children?.Any() == true)"" + @bind-SelectedNode=""selectedNode"" + @bind-ExpandedNodes=""expandedNodes"" + Virtualize> + + + @context.Text + + + +@code { + public class Item + { + public string Text { get; set; } + public IEnumerable Children { get; set; } + } + + protected override void OnInitialized() + { + Items = Enumerable.Range( 1, 4 ).Select( rootIndex => new Item + { + Text = $""Root Node {rootIndex}"", + Children = Enumerable.Range( 1, 100 ).Select( childIndex => new Item + { + Text = $""Root {rootIndex} - Child {childIndex}"", + Children = Enumerable.Empty() // No children for the child nodes in this example + } ) + } ).ToList(); + + base.OnInitialized(); + } + + IEnumerable Items; + + IList expandedNodes = new List(); + Item selectedNode; +}"; + public const string BasicVideoExample = @"