I need:
the node depth (root node =1, subnode = 2, next subnode = 3 and so on)
parent node
data object of parent node
traversal possibility of selected node up to root node (e.g. ParentNode.ParentNode.Name)
I need:
the node depth (root node =1, subnode = 2, next subnode = 3 and so on)
parent node
data object of parent node
traversal possibility of selected node up to root node (e.g. ParentNode.ParentNode.Name)
Hi @mjjalala,
This isn't currently available.
You can use the ParentItem property of a RadzenTreeItem. If it is null then the node is a root node. The Value property is the data object.
Hi
I have a Radzentree like this
I want to get MenuId for node when using ContextMent in RightClick as it is shown in the picture
@page "/"
@inject ContextMenuService ContextMenuService
<RadzenTree Data="@nodes" Expand="@OnTreeExpand" Change="@OnTreeSelectionChange" Style="width: 50%; height:520px" >
<RadzenTreeLevel Text="@(data => ((DataNode)data).Data.ToString())"
ChildrenProperty="Children"
Expanded="@(data => ((DataNode)data).Expanded)"
HasChildren="@(data => ((DataNode)data).Children != null)">
<Template>
<img src="" style="width: 20px; margin-right: 8px;" />
<b @oncontextmenu=@(args => ShowContextMenuWithItems(args)) @oncontextmenu:preventDefault="true"> @context.Text</b>
</Template>
</RadzenTreeLevel>
</RadzenTree>
<EventConsole @ref=@console Class="mt-4" />
@code {
EventConsole console;
public EventCallback<MouseEventArgs> Click { get; set; }
public class DataNode
{
public object Data { get; set; }
public int MenuId { get; set; }
public int MenuLevel { get; set; }
public bool Expanded { get; set; }
public IEnumerable<DataNode> Children { get; set; }
}
DataNode[] nodes = new DataNode[]
{
new DataNode
{
Data = "Root",
MenuId=1,
Expanded = false,
Children = new [] {
new DataNode { Data = "Child11",MenuId=2 , MenuLevel=1},
new DataNode { Data = "Child12" ,MenuId=3 , MenuLevel=1},
new DataNode { Data = "Child13",MenuId=4 , MenuLevel=1}
},
},
new DataNode
{
Data = "Root1",
MenuId=5,
Expanded = false,
Children = new [] {
new DataNode { Data = "Child21",MenuId=6},
new DataNode { Data = "Child22",MenuId=7},
new DataNode { Data = "Child23",MenuId=8}
},
},
new DataNode
{
Data = "Root3",
MenuId=9,
Expanded = false,
Children = new [] {
new DataNode { Data = "Child33" , MenuId=10},
new DataNode { Data = "Child33", MenuId=11},
new DataNode {
Data = "Child3 of parent",
MenuId=12,
Children = new [] {
new DataNode { Data = "Child2",MenuId=13},
new DataNode { Data = "Child2",MenuId=14},
new DataNode { Data = "Child2 of parent name Child3",MenuId=15 ,
Children = new [] {
new DataNode { Data = "Child23",MenuId=16},
new DataNode { Data = "Child23",MenuId=17},
new DataNode { Data = "Child23",MenuId=18}
}
}
}
}
},
}
};
void OnTreeExpand(TreeExpandEventArgs args)
{
console.Log($"TreeExpand: {args.Value}");
}
void OnTreeSelectionChange(TreeEventArgs args)
{
DataNode d = args.Value as DataNode;
console.Log($"TreeNode selected: {d.MenuId}");
d.Expanded = true;
}
void OnTreeMouseLeave(TreeEventArgs args)
{
DataNode d = args.Value as DataNode;
console.Log($"TreeNode selected: {d.MenuId}");
}
void ShowContextMenuWithItems(MouseEventArgs args)
{
ContextMenuService.Open(args,
new List<ContextMenuItem> {
new ContextMenuItem(){ Text = "Add", Value = 1 },
new ContextMenuItem(){ Text = "Delete", Value = 2 },
}, OnMenuItemClick);
}
void OnMenuItemClick(MenuItemEventArgs args)
{
console.Log($"Menu item with Value={args.Value} clicked");
if (!args.Value.Equals(3) && !args.Value.Equals(4))
{
ContextMenuService.Close();
}
}
}
What is your question?
How can I get MenuId for node when using ContextMent in RightClick , To be able to add or delete node dynamic
You can pass the data item from the Template:
<Template Context="node">
<b @oncontextmenu=@(args => ShowContextMenuWithItems(args, node.Value))>...</b>
</Template>
Is there a straight forward way to expand or collapse all of RadzenTree from an external button?
Is there a straight forward way to expand or collapse all of RadzenTree from an external button?
You can check this thread: Programmatically expand tree - #5 by Poojank
I mean, I need two buttons above Radzentree to Expand All , Collapse All
How can do this