Skip to main content
A newer version of this page is available. .

DxGrid.IsEditingNewRow() Method

Returns whether a new Grid row is currently being edited.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.1.dll

NuGet Package: DevExpress.Blazor

Declaration

public bool IsEditingNewRow()

Returns

Type Description
Boolean

true if a new row is currently being edited; otherwise, false.

Remarks

Users can employ an inline edit row or invoke a standard or pop-up edit form to edit data in the Grid. The EditMode property specifies the current edit mode.

Tip

For information on how to enable data editing, refer to the following topic: Edit Data in Blazor Grid.

Call the IsEditingNewRow method to identify whether the edit form or row is displayed for a new row. You can also call the IsEditingRow(Int32) method to check whether the edit form or row is displayed for the specified row. The IsEditing() method returns whether any Grid row is being edited.

@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable

<DxGrid Data="GridDataSource"
        EditModelSaving="OnEditModelSaving"
        KeyFieldName="EmployeeId"
        EditMode="GridEditMode.EditRow"
        @ref="MyGrid">
    <Columns>
        <DxGridCommandColumn DeleteButtonVisible="false" />
        <DxGridDataColumn FieldName="FirstName" />
        <DxGridDataColumn FieldName="LastName" />
        <DxGridDataColumn FieldName="Title" />
        <DxGridDataColumn FieldName="HireDate" />
    </Columns>
</DxGrid>

<br />
<DxButton Click="() => IsEditingInfo = MyGrid.IsEditing()">Is Editing</DxButton>
<DxButton Click="() => IsditingFirstRowEInfo = MyGrid.IsEditingRow(0)">Is Editing First Row</DxButton>
<DxButton Click="() => IsEditingNewRowInfo = MyGrid.IsEditingNewRow()">Is Editing New Row</DxButton>

<div><b>Is Editing</b>: @IsEditingInfo</div>
<div><b>Is Editing First Row</b>: @IsditingFirstRowEInfo</div>
<div><b>Is Editing New Row</b>: @IsEditingNewRowInfo</div>

@code {
    IEnumerable<object> GridDataSource { get; set; }
    NorthwindContext Northwind { get; set; }
    object SelectedDataItem { get; set; }
    IGrid MyGrid { get; set; }
    bool IsEditingInfo { get; set; }
    bool IsditingFirstRowEInfo { get; set; }
    bool IsEditingNewRowInfo { get; set; }

    protected override async Task OnInitializedAsync() {
        Northwind = NorthwindContextFactory.CreateDbContext();
        GridDataSource = await Northwind.Employees.ToListAsync();
        SelectedDataItem = GridDataSource.FirstOrDefault();
    }

    async Task OnEditModelSaving(GridEditModelSavingEventArgs e) {
        var editModel = (Employee)e.EditModel;
        var dataItem = e.IsNew ? new Employee() : Northwind.Employees.Find(editModel.EmployeeId);
        if (dataItem != null) {
            dataItem.FirstName = editModel.FirstName;
            dataItem.LastName = editModel.LastName;
            dataItem.Title = editModel.Title;
            dataItem.HireDate = editModel.HireDate;
            if (e.IsNew)
                await Northwind.AddAsync(dataItem);
            await Northwind.SaveChangesAsync();
            GridDataSource = await Northwind.Employees.ToListAsync();
        }
    }

    public void Dispose() {
        Northwind?.Dispose();
    }
}

Implements

See Also