Skip to main content
All docs
V24.1

TreeListChildrenLoadingOnDemandEventArgs Class

Stores data for the ChildrenLoadingOnDemand event.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.1.dll

NuGet Package: DevExpress.Blazor

Declaration

public class TreeListChildrenLoadingOnDemandEventArgs :
    TreeListChildrenLoadingEventArgs

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:

  1. Bind the Data parameter to a C# property.
  2. Populate this property with root data items in the OnInitialized or OnInitializedAsync lifecycle method.
  3. Specify the HasChildrenFieldName property. The component uses this property to determine which nodes require expand buttons.
  4. 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.

Read Tutorial: Bind Blazor TreeList to Data Run Demo: Load Data on Demand

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);
    }
}

Load Blazor TreeList Data on Demand

Limitations

The on-demand mode has the following specifics and limitations:

Inheritance

Object
TreeListChildrenLoadingEventArgs
TreeListChildrenLoadingOnDemandEventArgs
See Also