Skip to main content
All docs
V26.1
  • GridEditNewRowPosition Enum

    Lists values that specify the position of Grid UI elements used to create new rows.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.Grid.v26.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    public enum GridEditNewRowPosition

    Members

    Name Description
    Top

    The new item row is hidden. Once a user starts editing a new row, the Grid displays an edit form, edit row, or cell editors at the top of the current page.

    Bottom

    The new item row is hidden. Once a user starts editing a new row, the Grid displays an edit form, edit row, or cell editors at the bottom of the current page.

    FixedOnTop

    The Grid displays the new item row pinned to the top of the current page.

    LastRow

    The Grid displays the new item row after the last data row on the last page.

    Remarks

    The following example displays the new item row fixed to the top of the current Grid page:

    @using Microsoft.EntityFrameworkCore
    @inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
    @implements IDisposable
    
    <DxGrid Data="Data"
            KeyFieldName="EmployeeId"
            EditModelSaving="OnEditModelSaving"
            DataItemDeleting="OnDataItemDeleting"
            CustomizeEditModel="OnCustomizeEditModel"
            EditMode="GridEditMode.EditCell"
            EditNewRowPosition="GridEditNewRowPosition.FixedOnTop">
        <Columns>
            <DxGridDataColumn FieldName="TitleOfCourtesy" Caption="Courtesy Title" />
            <DxGridDataColumn FieldName="FirstName" />
            <DxGridDataColumn FieldName="LastName" />
            <DxGridDataColumn FieldName="Title" />
            <DxGridCommandColumn Width="30px" EditButtonVisible="false" SaveButtonVisible="false" />
        </Columns>
    </DxGrid>
    
    @code {
        IEnumerable<Employee> Data { get; set; }
        NorthwindContext Northwind { get; set; }
    
        protected override async Task OnInitializedAsync() {
            Northwind = NorthwindContextFactory.CreateDbContext();
            Data = await Northwind.Employees.ToListAsync();
        }
    
        void OnCustomizeEditModel(GridCustomizeEditModelEventArgs e) {
            if(e.IsNew) {
                var editModel = (Employee)e.EditModel;
                editModel.EmployeeId = Data.Max(x => x.EmployeeId) + 1;
            }
        }
    
        async Task OnEditModelSaving(GridEditModelSavingEventArgs e) {
            var editModel = (Employee)e.EditModel;
            if (e.IsNew)
                await Northwind.AddAsync(editModel);
            else
                e.CopyChangesToDataItem();
            // Post changes to the database.
            await Northwind.SaveChangesAsync();
            // Reload the entire Grid.
            Data = 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.
            Data = await Northwind.Employees.ToListAsync();
        }
    
        public void Dispose() {
            Northwind?.Dispose();
        }
    }
    

    Refer to the EditNewRowPosition property description for additional information.

    See Also