Good Evening,
currently porting a ASP.net app to blazor, i am missing some functionality in the RadzenTree component (or can't find it / find a way around it).
Missing methods:
i would like to, programmatically,
- expand a certain node (like _tree.ExpandNode(TreeNode x))
- expand all nodes at once after they are loaded (like _tree.ExpandAllNodes)
- get the currently selected tree node object (like TreeNode s = _tree.GetSelectedNode())
is this already possible and i missed it somehow?
Node Selection:
the args parameter currently contains a textstring and the object of the node that was clicked.
void OnTreeSelectionChange(TreeEventArgs args)
but 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)
this is how it currently looks like:
for example i click an entity node at node depth 3. i want to find out which "category" this node is in - this information is in the node in depth 2. since my entity nodes can be linked to multiple categories, there is no 1:1 relationship in the data model, so i have to use the tree to find my category=parent.
can we somehow access the nodes of the tree programmatically?
tree construction in code
finally, when constructing the tree, i currently do this with the TreeNodeExpand handler, but i feel this is from the wrong direction:
void OnTreeNodeExpand(TreeExpandEventArgs args)
{
if (args.Value is Group)
{
// TODO: how to make sure here that no expand icon appears if subnode has no children?
}
else if ((args.Value is Category))
{
var cat = args.Value as Category;
switch (_type)
{
case NavTreeNodeType.Check:
args.Children.Data = cat.CategoryCheckLinks;
args.Children.Text = GetTextForCheckNode;
args.Children.HasChildren = (o) => false; // level 3 nodes can't expand
args.Children.Template = TreeCheckTemplate;
break;
case NavTreeNodeType.Measure:
args.Children.Data = cat.CategoryMeasureLinks;
args.Children.Text = GetTextForMeasureNode;
args.Children.HasChildren = (o) => false; // level 3 nodes can't expand
args.Children.Template = TreeMeasureTemplate;
break;
}
}
else
{
// level 3 nodes have no children
}
}
RenderFragment<RadzenTreeItem> TreeCheckTemplate = (context) => builder =>
{
var c = context.Value as CategoryCheckLink;
MarkupString data = new MarkupString(Globals.quickHackTreeColorBox(c.Check.Name, c.Check.Published));
builder.AddContent(0, data);
};
// template for measure node
RenderFragment<RadzenTreeItem> TreeMeasureTemplate = (context) => builder =>
{
var m = context.Value as CategoryMeasureLink;
MarkupString data = new MarkupString(Globals.quickHackTreeColorBox(m.Measure.Name, m.Measure.Published));
builder.AddContent(0, data);
};
so for example, when i would like to make sure, that nodes at level 2 (categories) have no "expand" icon on the left side, i have to put code in the expand handler for level 1 (groups). i failed to cook up some code to do that.
it would be much easier for me to just precreate the entire tree structure after querying the database, instead of creating it step by step after user interaction? is this possible? did i miss this approach in the examples somewhere?
pseudo code:
foreach (var g in groups)
{
TreeNode gNode = _tree.CreateNode(g.Name);
gNode.Data = g;
foreach (var c in g.categories)
{
TreeNode cNode = gNode.CreateNode(c.Name);
cNode.Data = c;
// find entities in this category
var measures = context.CategoryMeasureLinks.Where(x=>x.categoryid == c.id).ToList();
foreach(var m in measures)
{
TreeNode mNode = cNode.CreateNode(m.Name);
mNode.Data = m;
}
}
}