I am trying to use the TreeView with a custom DataAdaptor to fully customize the way the data is loaded from the server. I created a custom DataAdaptor by implementing the ReadAsync method. For the purpose of testing, I added as Task.Delay that is invoked when the root node gets expanded. However, when I expand the root node, nothing happens at all until the ReadAsync method is fully completed. Only then, the expand spinner gets shown for a brief moment. But that does not really help. The expand spinner should show before the ReadAsync method starts executing and hide after the ReadAsync method is finished.
<SfTreeView TValue="OrgUnit">
<TreeViewFieldsSettings TValue="OrgUnit" Id="Id" Text="Name" ParentID="ParentId" HasChildren="HasChildren" Expanded="Expanded">
<Syncfusion.Blazor.Data.SfDataManager AdaptorInstance="@typeof(CustomAdaptor)" Adaptor="Syncfusion.Blazor.Adaptors.CustomAdaptor" />
</TreeViewFieldsSettings>
</SfTreeView>
@code {
public class CustomAdaptor : DataAdaptor
{
public override async Task<object> ReadAsync(DataManagerRequest dataManagerRequest, string key = null)
{
int? parentId = null;
// ... (load parent id)
List<OrgUnit> OrgUnits = new List<OrgUnit>();
if(parentId == 1)
{
// Delay execution upon expanding the root node
await Task.Delay(2000);
OrgUnits.Add(new OrgUnit()
{
Id = 2, ParentId = 1, Name = "Child",
Expanded = false, HasChildren = false
});
}
else
{
OrgUnits.Add(new OrgUnit()
{
Id = 1, ParentId = null, Name = "Root",
Expanded = false, HasChildren = true
});
}
return (object)OrgUnits;
}
}
}