Skip to main content
All docs
V25.1
  • DxTreeListCommandColumn.HeaderTemplate Property

    Specifies a template used to display the command column header.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v25.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    [Parameter]
    public RenderFragment<TreeListCommandColumnHeaderTemplateContext> HeaderTemplate { get; set; }

    Property Value

    Type Description
    RenderFragment<TreeListCommandColumnHeaderTemplateContext>

    A template for the command column header.

    Remarks

    The command column displays predefined New, Edit, and Delete buttons for data rows in display mode. In EditRow and EditCell edit modes, this column displays Save and Cancel buttons for the edited row. In the filter row, the column displays the Clear button.

    Blazor TreeList Command Column

    Read Tutorial: Editing and Validation in Blazor TreeList Read Tutorial: Templates in Blazor TreeList

    Define the HeaderTemplate to display custom content in the command column header. Use the template’s context parameter to access the CommandColumn object. The TreeList object allows you to access the component and call edit-related methods. For instance, call the StartEditNewRowAsync method to start editing a new data row.

    Specify the CellDisplayTemplate to display custom command elements for cells in display mode. The CellEditTemplate allows you to display custom command elements for cells in edit mode. To display custom content in the filter row, define the FilterRowCellTemplate.

    Note

    Add, Edit, and Delete operations can be temporarily unavailable if you bind the TreeList to the GridDevExtremeDataSource or load data on demand. Use the following template parameters to specify the enabled or disabled state for custom command elements:

    The following code snippet displays icons instead of default command buttons:

    @inject EmployeeTaskService EmployeeTaskService
    
    <DxTreeList @ref="MyTreeList"
                Data="TreeListData"
                KeyFieldName="Id"
                ParentKeyFieldName="ParentId"
                EditMode="TreeListEditMode.EditForm"
                EditModelSaving="TreeList_EditModelSaving"
                DataItemDeleting="TreeList_DataItemDeleting"
                CustomizeEditModel="TreeList_CustomizeEditModel">
        <Columns>
            <DxTreeListCommandColumn Width="90px">
                <HeaderTemplate>
                    <a class="oi oi-plus" @onclick="@(() => MyTreeList.StartEditNewRowAsync())" style="text-decoration: none;" href="javascript:void(0);"></a>
                </HeaderTemplate>
                <CellDisplayTemplate>
                    <a class="oi oi-pencil" @onclick="@(() => MyTreeList.StartEditRowAsync(context.VisibleIndex))" style="text-decoration: none;" href="javascript:void(0);"></a>
                    <a class="oi oi-plus" @onclick="@(() => MyTreeList.StartEditNewRowAsync(context.VisibleIndex))" style="text-decoration: none;" href="javascript:void(0);"></a>
                    <a class="oi oi-x" @onclick="@(() => MyTreeList.ShowRowDeleteConfirmation(context.VisibleIndex))" style="text-decoration: none;" href="javascript:void(0);"></a>
                </CellDisplayTemplate>
            </DxTreeListCommandColumn>
            <DxTreeListDataColumn FieldName="Name" Caption="Task" />
            <DxTreeListDataColumn FieldName="EmployeeName" />
            <DxTreeListDataColumn FieldName="StartDate" />
            <DxTreeListDataColumn FieldName="DueDate" />
        </Columns>
        <EditFormTemplate Context="EditFormContext">
            <DxFormLayout CssClass="w-100">
                <DxFormLayoutItem Caption="Task:" ColSpanMd="6">
                    @EditFormContext.GetEditor("Name")
                </DxFormLayoutItem>
                <DxFormLayoutItem Caption="Employee Name:" ColSpanMd="6">
                    @EditFormContext.GetEditor("EmployeeName")
                </DxFormLayoutItem>
                <DxFormLayoutItem Caption="Start Date:" ColSpanMd="6">
                    @EditFormContext.GetEditor("StartDate")
                </DxFormLayoutItem>
                <DxFormLayoutItem Caption="Due Date:" ColSpanMd="6">
                    @EditFormContext.GetEditor("DueDate")
                </DxFormLayoutItem>
            </DxFormLayout>
        </EditFormTemplate>
    </DxTreeList>
    
    @code {
        ITreeList MyTreeList { get; set; }
        List<EmployeeTask> TreeListData { get; set; }
    
        protected override void OnInitialized() {
            TreeListData = EmployeeTaskService.GenerateData();
        }
        void TreeList_CustomizeEditModel(TreeListCustomizeEditModelEventArgs e) {
            if (e.IsNew) {
                var newTask = (EmployeeTask)e.EditModel;
                newTask.Id = TreeListData.Max(x => x.Id) + 1;
                if (e.ParentDataItem != null) {
                    newTask.ParentId = ((EmployeeTask)e.ParentDataItem).Id;
                }
            }
        }
        async Task TreeList_EditModelSaving(TreeListEditModelSavingEventArgs e) {
            if (e.IsNew)
                TreeListData.Add((EmployeeTask)e.EditModel);
            else
                e.CopyChangesToDataItem();
        }
        async Task TreeList_DataItemDeleting(TreeListDataItemDeletingEventArgs e) {
            TreeListData.Remove((EmployeeTask)e.DataItem);
        }
    }
    

    Blazor TreeList Editing Custom Command Buttons

    Implements

    See Also