DxTreeList.ChildrenLoadingOnDemand Event
Allows you to populate a node with child nodes. The TreeList component raises this event when the node is expanded for the first time.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.1.dll
NuGet Package: DevExpress.Blazor
Declaration
[Parameter]
public Func<TreeListChildrenLoadingOnDemandEventArgs, Task> ChildrenLoadingOnDemand { get; set; }
Parameters
Type | Description |
---|---|
TreeListChildrenLoadingOnDemandEventArgs | An object that contains data for this event. |
Remarks
The TreeList component gives you an option to initially load only root nodes. It retrieves child nodes on demand when a user expands a node for the first time. Follow the steps below to enable this behavior:
- Bind the Data parameter to a C# property.
- Populate this property with root data items in the OnInitialized or OnInitializedAsync lifecycle method.
- Specify the HasChildrenFieldName property. The component uses this property to determine which nodes require expand buttons.
- Handle the
ChildrenLoadingOnDemand
event. In the event handler, use the Parent event argument to determine the processed node and assign the node’s children to the Children collection.
Example
In the following example, the TreeList component displays the file structure:
@inject FileSystemDataProvider FileSystemDataProvider
<DxTreeList Data="TreeListData"
HasChildrenFieldName="HasChildren"
ChildrenLoadingOnDemand="TreeList_ChildrenLoadingOnDemand"
CustomizeCellDisplayText="TreeList_CustomizeCellDisplayText">
<Columns>
<DxTreeListDataColumn FieldName="Name" />
<DxTreeListDataColumn FieldName="Type" Width="100" />
<DxTreeListDataColumn FieldName="DateModified" Width="120" />
<DxTreeListDataColumn FieldName="Size" Width="100" />
</Columns>
</DxTreeList>
@code {
object TreeListData { get; set; }
protected override async Task OnInitializedAsync() {
TreeListData = await FileSystemDataProvider.GetRootItemsAsync();
}
Task TreeList_ChildrenLoadingOnDemand(TreeListChildrenLoadingOnDemandEventArgs e) {
var item = e.Parent as FileSystemDataItem;
e.Children = item.Children;
return Task.CompletedTask;
}
void TreeList_CustomizeCellDisplayText(TreeListCustomizeCellDisplayTextEventArgs e) {
if(e.FieldName == "Size") {
var item = (FileSystemDataItem)e.DataItem;
e.DisplayText = GetSizeColumnDisplayText(item.Type, item.Size);
}
}
string GetSizeColumnDisplayText(FileType fileType, long size) {
if(fileType == FileType.Folder)
return null;
if(size >= 1024)
return string.Format("{0:### ### ###} KB", size / 1024);
return string.Format("{0} Bytes", size);
}
}
Limitations
The on-demand mode has the following specifics and limitations:
- A filter operation forces the component to load all data.
- Summary calculation is not supported.
- ExpandAll() and CollapseAll() methods are not supported.
AllPages
mode of the Select All checkbox is not supported.- The SelectAllAsync and DeselectAllAsync method calls force the component to load all data.
- The second call to the SelectAllAsync or DeselectAllAsync method cancels the operation initiated by the previously called method.
- Sort and filter operations cancel incomplete “select all” and “deselect all” processes.
- Call the WaitForRemoteSourceRowLoadAsync method before those that accept a row’s visible index as a parameter (SelectRow, ExpandRow, and so on) to ensure that the specified data row is loaded.
See Also