Skip to main content

DxGrid.IsEditingNewRow() Method

Returns whether a new Grid row is being edited.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public bool IsEditingNewRow()

Returns

Type Description
Boolean

true if a new row is being edited; false if an existing row is being edited.

Remarks

Call the IsEditing() method to check whether the Grid is in edit mode. The IsEditingRow(Int32) method allows you to identify whether the specified row is being edited. The IsEditingNewRow method returns whether a new or existing row is in edit mode.

Tip

For information on how to enable data editing, refer to the following topic: Editing and Validation in Blazor Grid.

@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;
        // 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();
    }

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

Implements

See Also