DxGrid.StartEditRowAsync(Int32, String) Method
Starts editing the row with the specified visible index.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.2.dll
NuGet Package: DevExpress.Blazor
Declaration
public Task StartEditRowAsync(
int visibleIndex,
string fieldName = null
)
Parameters
Name | Type | Description |
---|---|---|
visibleIndex | Int32 | A row visible index. |
Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
fieldName | String | null | A data source field name that defines the column cell in which an editor in EditCell mode is to be displayed. If this parameter is omitted, the method displays an editor in the first data column whose DataRowEditorVisible equals |
Returns
Type | Description |
---|---|
Task | A task that is completed when the row is in edit mode. |
Remarks
The Grid’s EditMode property specifies how users edit Grid data. The StartEditRowAsync
method behaves as follows depending on the active edit mode:
- EditForm (Default)
- Displays the edit form for the row with the specified visible index and focuses the first editor in this form.
- PopupEditForm
- Invokes the pop-up edit form for the row with the specified visible index and focuses the first editor in this form.
- EditRow
- Displays the edit row for the row with the specified visible index and focuses the first editor in this row.
- EditCell
Displays and focuses an in-place editor in the cell associated with the specified field in the row with the target visible index. 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 equalstrue
.
Declare a DxGridCommandColumn object in the Columns template to display predefined New, Edit, and Delete command buttons in the Grid component. Alternatively, you can create custom command elements inside or outside the Grid. Handle a custom element’s click event and call the StartEditRowAsync
method to start editing the row with the specified visible index.
Note
The Grid bound to an Instant Feedback Data Source or GridDevExtremeDataSource loads data asynchronously in small portions (instead of the entire dataset). Before you call the StartEditRowAsync
method, call the WaitForRemoteSourceRowLoadAsync(Int32) method to ensure that the specified data row is loaded.
The following example creates buttons used to edit and delete a row whose visible index is 0
:
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable
<DxGrid Data="GridDataSource"
EditModelSaving="OnEditModelSaving"
DataItemDeleting="OnDataItemDeleting"
KeyFieldName="EmployeeId"
EdiMode="GridEditMode.EditRow"
@ref="MyGrid">
<Columns>
<DxGridCommandColumn Width="150" />
<DxGridDataColumn FieldName="FirstName" />
<DxGridDataColumn FieldName="LastName" />
<DxGridDataColumn FieldName="Title" />
<DxGridDataColumn FieldName="HireDate" />
</Columns>
</DxGrid>
<br />
<DxButton Click="() => MyGrid.StartEditRowAsync(0)">Edit First Row</DxButton>
<DxButton Click="() => MyGrid.ShowRowDeleteConfirmation(0)">Delete First Row</DxButton>
@code {
IEnumerable<object> GridDataSource { get; set; }
NorthwindContext Northwind { get; set; }
IGrid MyGrid { get; set; }
protected override async Task OnInitializedAsync() {
Northwind = NorthwindContextFactory.CreateDbContext();
GridDataSource = await Northwind.Employees.ToListAsync();
}
async Task OnEditModelSaving(GridEditModelSavingEventArgs e) {
var editModel = (Employee)e.EditModel;
// Assign changes from the edit model to the data item.
if (e.IsNew)
await Northwind.AddAsync(editModel);
else
e.CopyChangesToDataItem();
// Post changes to the database.
await Northwind.SaveChangesAsync();
// Reload the entire Grid.
GridDataSource = await Northwind.Employees.ToListAsync();
}
async Task OnDataItemDeleting(GridDataItemDeletingEventArgs e) {
// Remove the data item from the database.
Northwind.Remove(e.DataItem);
await Northwind.SaveChangesAsync();
// Reload the entire Grid.
GridDataSource = await Northwind.Employees.ToListAsync();
}
public void Dispose() {
Northwind?.Dispose();
}
}
For information on how to enable data editing, refer to the following topic: Edit Data in Blazor Grid.