DxTreeList.StartEditNewRowAsync(String) Method
Starts editing a new root node.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.2.dll
NuGet Package: DevExpress.Blazor
Declaration
public Task StartEditNewRowAsync(
string fieldName = null
)
Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
fieldName | String | null | A field name that defines the column cell where to display an editor. If this parameter is omitted or the EditMode differs from |
Returns
Type | Description |
---|---|
Task | A task that is completed when the row is in edit mode. |
Remarks
The TreeList’s EditMode property specifies how users edit TreeList data. The StartEditNewRowAsync
method behaves as follows depending on the active edit mode:
- EditRow (Default)
- Displays the edit row for the new root node and focuses the first editor in the edit row.
- EditForm
- Displays the inline edit form for the new root node and focuses the first editor in this form.
- PopupEditForm
- Invokes the pop-up edit form for the new root node and focuses the first editor in this form.
- EditCell
Displays and focuses an in-place editor in the cell associated with the specified field of the new root data item. The method ignores the
fieldName
parameter in the following cases:- No column is bound to the specified field.
- The DataRowEditorVisible property of the column bound to the specified field is disabled.
When the
fieldName
parameter is omitted or ignored, the method displays an editor in the first data column whose DataRowEditorVisible istrue
.
Declare a DxTreeListCommandColumn object in the Columns template to display predefined New, Edit, and Delete command buttons in the TreeList component. Alternatively, you can create custom command elements inside or outside the TreeList. Handle a custom element’s click event and call the StartEditNewRowAsync
method to start editing the new root node.
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);
}
}
Refer to the following topic for more information: Editing and Validation in Blazor TreeList.