DxTreeList.CustomizeDataRowEditor Event
Allows you to customize a cell editor in a data row.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.2.dll
NuGet Package: DevExpress.Blazor
Declaration
[Parameter]
public Action<TreeListCustomizeDataRowEditorEventArgs> CustomizeDataRowEditor { get; set; }
Parameters
Type | Description |
---|---|
TreeListCustomizeDataRowEditorEventArgs | An object that contains data for this event. |
Remarks
The TreeList generates and configures cell editors for individual columns based on associated data types. You can use the EditSettings property to customize a column’s editor settings. The TreeList displays these cell editors in the filter row and in data rows during edit operations.
Handle the CustomizeDataRowEditor
event to customize a data row editor separately from the filter row editor.
The following code snippet handles the CustomizeDataRowEditor
event to customize the StartDate column editor in two ways:
- Limit available start dates for new tasks.
- Prohibit start date modification for existing tasks.
@inject EmployeeTaskService EmployeeTaskService
<DxTreeList Data="TreeListData"
KeyFieldName="Id"
ParentKeyFieldName="ParentId"
ShowFilterRow="true"
CustomizeDataRowEditor="TreeList_CustomizeDataRowEditor"
EditModelSaving="TreeList_EditModelSaving"
DataItemDeleting="TreeList_DataItemDeleting"
CustomizeEditModel="TreeList_CustomizeEditModel">
<Columns>
<DxTreeListCommandColumn />
<DxTreeListDataColumn FieldName="Name" Caption="Task" />
<DxTreeListDataColumn FieldName="EmployeeName" />
<DxTreeListDataColumn FieldName="StartDate" />
<DxTreeListDataColumn FieldName="DueDate" />
</Columns>
</DxTreeList>
@code {
List<EmployeeTask> TreeListData { get; set; }
protected override void OnInitialized() {
TreeListData = EmployeeTaskService.GenerateData();
}
void TreeList_CustomizeDataRowEditor(TreeListCustomizeDataRowEditorEventArgs e) {
if (e.FieldName == "StartDate") {
var StartDateSettings = e.EditSettings as IDateEditSettings;
if (e.IsNewRow) {
// Limits the available start date for new tasks
StartDateSettings.MinDate = @DateTime.Today;
StartDateSettings.MaxDate = @DateTime.Today.AddDays(14);
} else {
// Disables the start date editing
StartDateSettings.Enabled = false;
StartDateSettings.ShowDropDownButton = false;
}
}
}
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);
}
}