RadzenTreeLevel Expanded passes on wrong data context #854

Closed
opened 2026-01-29 17:45:18 +00:00 by claunia · 1 comment
Owner

Originally created by @UrielMhezzek on GitHub (May 20, 2023).

Ich use a simple normal TreeNode with childenobjects

public class TreeNode
    {
        public string Name { get; set; }
        public string FullPath { get; set; }
        public List<TreeNode> Children { get; set; }
}

In my example i have a chosen path, that should expand all nodes in view in the path von the chosen path.

My function is simple

private bool ShouldExpand(object data)
        {
            if (selection == null) return false;

            var selPath = ((TreeNode)selection).FullPath;
            var curNodePath = ((TreeNode)data).FullPath;

            return selPath.StartsWith(curNodePath) || selPath == curNodePath;
        }

First, i tried this:

<RadzenTreeLevel Text=@GetTextForNode Template=@FileOrFolderTemplate Expanded="ShouldExpand" />

This not worked. I get every time as data the top level node. Later i tried this out. This works.

void ExpandNode(TreeExpandEventArgs args)
        {
            TreeNode node = (TreeNode)args.Value;

            args.Children.Data = node.Children;
            args.Children.Text = GetTextForNode;
            args.Children.HasChildren = (node) => ((TreeNode)node).Children?.Count() > 0;
            args.Children.Template = FileOrFolderTemplate;
            args.Children.Expanded = (o) => ShouldExpand(node);
        }

Finally, I think that the expand function by default gets the wrong object (top-level-data-object) and not the currently evaluated object. I think the Problem is here

c80fcc5494/Radzen.Blazor/RadzenTree.razor.cs (LL211C80-L211C80)

Originally created by @UrielMhezzek on GitHub (May 20, 2023). Ich use a simple normal TreeNode with childenobjects ``` public class TreeNode { public string Name { get; set; } public string FullPath { get; set; } public List<TreeNode> Children { get; set; } } ``` In my example i have a chosen path, that should expand all nodes in view in the path von the chosen path. My function is simple ``` private bool ShouldExpand(object data) { if (selection == null) return false; var selPath = ((TreeNode)selection).FullPath; var curNodePath = ((TreeNode)data).FullPath; return selPath.StartsWith(curNodePath) || selPath == curNodePath; } ``` First, i tried this: ``` <RadzenTreeLevel Text=@GetTextForNode Template=@FileOrFolderTemplate Expanded="ShouldExpand" /> ``` This not worked. I get every time as data the top level node. Later i tried this out. This works. ``` void ExpandNode(TreeExpandEventArgs args) { TreeNode node = (TreeNode)args.Value; args.Children.Data = node.Children; args.Children.Text = GetTextForNode; args.Children.HasChildren = (node) => ((TreeNode)node).Children?.Count() > 0; args.Children.Template = FileOrFolderTemplate; args.Children.Expanded = (o) => ShouldExpand(node); } ``` Finally, I think that the expand function by default gets the wrong object (top-level-data-object) and not the currently evaluated object. I think the Problem is here https://github.com/radzenhq/radzen-blazor/blob/c80fcc549496c996ebb03c9e53d51b9dff873dd4/Radzen.Blazor/RadzenTree.razor.cs#LL211C80-L211C80
Author
Owner

@akorchev commented on GitHub (May 23, 2023):

Hi @UrielMhezzek,

The linked code is this:

builder.AddAttribute(1, nameof(RadzenTreeItem.Text), text(data));
builder.AddAttribute(2, nameof(RadzenTreeItem.Value), data);
builder.AddAttribute(3, nameof(RadzenTreeItem.HasChildren), hasChildren(data));
builder.AddAttribute(4, nameof(RadzenTreeItem.Template), template);
builder.AddAttribute(5, nameof(RadzenTreeItem.Expanded), expanded(data));

If expanded were wrong so are Text, Value, HasChildren and Template. We however do not reproduce such a problem. Can you reproduce this issue in our online demos? For example here: https://blazor.radzen.com/tree-file-system

@akorchev commented on GitHub (May 23, 2023): Hi @UrielMhezzek, The linked code is this: ``` builder.AddAttribute(1, nameof(RadzenTreeItem.Text), text(data)); builder.AddAttribute(2, nameof(RadzenTreeItem.Value), data); builder.AddAttribute(3, nameof(RadzenTreeItem.HasChildren), hasChildren(data)); builder.AddAttribute(4, nameof(RadzenTreeItem.Template), template); builder.AddAttribute(5, nameof(RadzenTreeItem.Expanded), expanded(data)); ``` If expanded were wrong so are Text, Value, HasChildren and Template. We however do not reproduce such a problem. Can you reproduce this issue in our online demos? For example here: https://blazor.radzen.com/tree-file-system
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#854