I'm trying to use a method to get childen when the OnExpand is fired. I'm not sure how implement HasChildren to accomplish this. I kinda feel it's something simple but I'm not sure how to implement it.
private bool HasChildren(long parent)
{
return Task.Run(() => _inventoryService.GetInventoryCategories(parent)).Result.Any();
}
internal async Task OnExpand(TreeExpandEventArgs args)
{
if (args.Value is not null)
{
var category = args.Value as InventoryCategoryModel;
if (category != null)
{
var subCategories = await _inventoryService.GetInventoryCategories((long)category.Id);
args.Children.Data = subCategories;
args.Children.TextProperty = nameof(InventoryCategoryModel.ShortDescription);
args.Children.HasChildren = (bool) => HasChildren([Needs to be the Id column from the ef core dataset]);
}
}
}
Got It! Here is the working code in case anyone else stumbles upon the post. FYI . this is a simple category tree with a ParentId that points to an Id column in the same table.
<RadzenTree Data=@Categories Expand=@OnExpand Style="height: 300px">
<RadzenTreeLevel HasChildren="@(data => HasChildren((long)((InventoryCategoryModel)data).Id))"
TextProperty="@nameof(InventoryCategoryModel.ShortDescription)" />
</RadzenTree>
private bool HasChildren(long parent)
{
return Task.Run(() => _inventoryService.GetInventoryCategories(parent)).Result.Any();
}
internal async Task OnExpand(TreeExpandEventArgs args)
{
if (args.Value is not null)
{
var category = args.Value as InventoryCategoryModel;
if (category != null)
{
var subCategories = await _inventoryService.GetInventoryCategories((long)category.Id);
args.Children.Data = subCategories;
args.Children.TextProperty = nameof(InventoryCategoryModel.ShortDescription);
args.Children.HasChildren = data => HasChildren((long)((InventoryCategoryModel)data).Id);
}
}
}