DxTreeListCommandColumn.CellEditTemplate Property
Specifies a template used to display the command column’s edit cell.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.2.dll
NuGet Package: DevExpress.Blazor
Declaration
[Parameter]
public RenderFragment<TreeListCommandColumnCellEditTemplateContext> CellEditTemplate { get; set; }
Property Value
Type | Description |
---|---|
RenderFragment<TreeListCommandColumnCellEditTemplateContext> | A template for the command column’s edit cell. |
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.
Define the CellEditTemplate
to display custom command elements for the edited row. Use the template’s context parameter to access CommandColumn, DataItem, and ParentDataItem objects. The TreeList object allows you to access the TreeList component and call the following edit-related methods:
- SaveChangesAsync()
- Triggers validation and raises the EditModelSaving event if validation succeeds. The method immediately raises this event if validation is disabled.
- CancelEditAsync()
- Cancels row editing and discards changes.
Specify the CellDisplayTemplate to display custom command elements for cells in display mode. Use HeaderTemplate and FilterRowCellTemplate to display custom content in the command column header and filter row.
The following example hides the predefined Save and Cancel buttons and implements custom buttons within the edit row:
@inject EmployeeTaskService EmployeeTaskService
<DxTreeList @ref="MyTreeList"
Data="TreeListData"
KeyFieldName="Id"
ParentKeyFieldName="ParentId"
EditModelSaving="TreeList_EditModelSaving"
DataItemDeleting="TreeList_DataItemDeleting"
CustomizeEditModel="TreeList_CustomizeEditModel">
<Columns>
<DxTreeListCommandColumn Width="200px">
<CellEditTemplate>
<DxButton Click="@(() => MyTreeList.SaveChangesAsync())" Text="Update" />
<DxButton Click="@(() => MyTreeList.CancelEditAsync())" Text="Discard" />
</CellEditTemplate>
</DxTreeListCommandColumn>
<DxTreeListDataColumn FieldName="Name" Caption="Task" />
<DxTreeListDataColumn FieldName="EmployeeName" />
<DxTreeListDataColumn FieldName="StartDate" />
<DxTreeListDataColumn FieldName="DueDate" />
</Columns>
</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);
}
}