Back to Devexpress

Get Started with Blazor TreeList

blazor-405000-components-treelist-get-started-with-treelist.md

latest8.4 KB
Original Source

Get Started with Blazor TreeList

  • Jan 20, 2026
  • 7 minutes to read

This tutorial describes how to create a simple Blazor application that uses a DevExpress TreeList component.

The following example contains full source code for this tutorial: Blazor TreeList - Getting Started.

Create an Application

Create an application as described in the following topic: Get Started With DevExpress Components for Blazor.

Enable Interactivity on a Page

Blazor TreeList supports static render mode to display static data in a single page. For other features, you need to enable interactivity on a Razor page and allow the TreeList component to execute scripts and display data.

razor
@rendermode InteractiveServer

Prepare a Data Source

  1. Add the EmployeeTask class to your project:

  2. Add the EmployeeTaskService class to your project:

  3. Register the EmployeeTaskService in the Program.cs file.

Add a TreeList and Bind It to Data

  1. Add <DxTreeList></DxTreeList> tags to the Index.razor page.

  2. Inject the EmployeeTaskService to the page.

  3. In the @code block, declare a list of EmployeeTask objects. Populate this list in the OnInitialized lifecycle method.

  4. Bind the Data property to the list.

  5. Specify KeyFieldName and ParentKeyFieldName properties to build a tree structure.

Refer to the following topic for additional information: Bind Blazor TreeList to Data.

Add Columns

  1. Add five DxTreeListDataColumn objects to the Columns collection.
  2. Use the FieldName property to bind columns to data source fields. Note that the FieldName property value must be unique for each data column.
  3. Optional. Specify the following settings to customize these columns:
razor
<DxTreeList Data="@Data" KeyFieldName="Id" ParentKeyFieldName="ParentId">
    <Columns>
        <DxTreeListDataColumn FieldName="Name" Caption="Task" Width="40%"/>
        <DxTreeListDataColumn FieldName="EmployeeName" />
        <DxTreeListDataColumn FieldName="StartDate" MinWidth="100" />
        <DxTreeListDataColumn FieldName="DueDate" MinWidth="100" />
        <DxTreeListDataColumn FieldName="Progress" DisplayFormat="{0}%" />
    </Columns>
</DxTreeList>

Sort Data

The TreeList component allows users to sort data by multiple columns. Specify SortOrder and SortIndex properties to configure initial sort settings.

razor
<DxTreeListDataColumn FieldName="DueDate"
                      MinWidth="100"
                      SortOrder="TreeListColumnSortOrder.Ascending"
                      SortIndex="0" />
<DxTreeListDataColumn FieldName="Progress"
                      SortOrder="TreeListColumnSortOrder.Descending"
                      SortIndex="1" />

Filter Data

  1. Set the ShowFilterRow property to true to display the filter row that allows users to filter data.

  2. Use the FilterTreeMode property to specify how the TreeList component displays filtered nodes:

  3. Specify FilterRowValue and FilterRowOperatorType properties to configure initial filter row values.

razor
<DxTreeList Data="@Data"
            KeyFieldName="Id"
            ParentKeyFieldName="ParentId"
            ShowFilterRow="true"
            FilterTreeMode="TreeListFilterTreeMode.EntireBranch">
    <Columns>
        <DxTreeListDataColumn FieldName="EmployeeName"
                              FilterRowValue='"John"'
                              FilterRowOperatorType="TreeListFilterRowOperatorType.Contains" />
        <!-- ... -->
    </Columns>
</DxTreeList>

Add a Total Summary

Follow the steps below to display a total summary in the TreeList component:

  1. Add a DxTreeListSummaryItem object to the TotalSummary collection.
  2. Specify the item’s SummaryType and FieldName properties.
  3. Optional. Specify other item settings (FooterColumnName, DisplayText, and so on).
razor
<DxTreeList Data="@Data" ... >
    <TotalSummary>
        <DxTreeListSummaryItem FieldName="Name" SummaryType="TreeListSummaryItemType.Count" />
        <DxTreeListSummaryItem FieldName="Progress" SummaryType="TreeListSummaryItemType.Avg" />
    </TotalSummary>
</DxTreeList>

Edit Data

Follow the steps below to enable data editing:

  1. Declare a DxTreeListCommandColumn object in the Columns collection. The command column displays buttons that allow users to add, edit, and delete rows.
  2. Handle the CustomizeEditModel event to initialize an edit model for new data rows.
  3. Handle EditModelSaving and DataItemDeleting events to post changes to the data source.
razor
<DxTreeList Data="@Data"
            KeyFieldName="Id"
            ParentKeyFieldName="ParentId"
            EditModelSaving="TreeList_EditModelSaving"
            DataItemDeleting="TreeList_DataItemDeleting"
            CustomizeEditModel="TreeList_CustomizeEditModel" ...>
    <Columns>
        <DxTreeListCommandColumn Width="200px"/>
        @* ... *@
    </Columns>
</DxTreeList>

@code {
    List<EmployeeTask> Data { get; set; }

    void TreeList_CustomizeEditModel(TreeListCustomizeEditModelEventArgs e) {
        if(e.IsNew) {
            var newTask = (EmployeeTask)e.EditModel;
            newTask.Id = Data.Max(x => x.Id) + 1;
            if(e.ParentDataItem != null)
                newTask.ParentId = ((EmployeeTask)e.ParentDataItem).Id;
        }
    }
    async Task TreeList_EditModelSaving(TreeListEditModelSavingEventArgs e) {
        if(e.IsNew)
            Data.Add((EmployeeTask)e.EditModel);
        else
            e.CopyChangesToDataItem();
    }
    async Task TreeList_DataItemDeleting(TreeListDataItemDeletingEventArgs e) {
        Data.Remove((EmployeeTask)e.DataItem);
    }
    protected override void OnInitialized() {
        Data = EmployeeTaskService.GenerateData();
    }
}

Refer to the following topic for additional information: Editing and Validation in Blazor TreeList.

More Features

For additional information about TreeList features, refer to the following root topic: Blazor TreeList.