My tree view

Actual Need to like this

My tree view

Actual Need to like this

Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Nitin KumarRank #3,113 · 460 reputationPosted Sep 19, 2023, 4:55 AM EDT
Replace
"child-icon-class"with the CSS class that represents the icon for child and sub-child nodes.We use the
itemTemplateproperty to customize the rendering of each node. ThechildTemplateJavaScript function is called for each node in the TreeView, and it conditionally adds an icon for nodes with children.Make sure to define your CSS classes for the icons (
parent-icon-classandchild-icon-class) in your CSS stylesheet, or you can use an icon library like FontAwesome or Material Icons to set the icons.Mithun Pradhan194 reputationPosted Sep 20, 2023, 9:52 AM EDT
Solved
----------------------
public async Task OnGetAsync()
{
FruitsListViewModel= await _userService.GetFruitsListAsync(Id);
TreeViewModel = new List
foreach (var data in FruitsListViewModel)
{
var treeViewNode = new
{
data.Id,
data.parentId,
data.Name,
HasChild = data.FruitsCategory!= 3,
Expanded = !data.IsDefault,
data.IsDefault,
Icon = GetIcon(data)
};
TreeViewModel.Add(treeViewNode);
}
}
private string GetIcon(FruitsListViewModel data)
{
switch (data.FruitsCategory)
{
case 1:
return "fruits";
case 2:
return "fruits-item";
case 3:
return "fruits-label";
case 4:
return "fruits-edit";
default:
return "";
}
}