GridEditNewRowPosition Enum
Lists values that specify the position of Grid UI elements used to create new rows.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.2.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">
<HeaderTemplate>
<DxButton IconCssClass="grid-icon grid-icon-add"
RenderStyle="ButtonRenderStyle.Link"
aria-label="Add"
Click="@(() => Grid.StartEditNewRowAsync())" />
</HeaderTemplate>
<CellDisplayTemplate>
<div class="grid-cell-align-center">
<DxButton IconCssClass="grid-icon grid-icon-delete"
RenderStyle="ButtonRenderStyle.Link"
aria-label="Delete"
Click="@(() => Grid.ShowRowDeleteConfirmation(context.VisibleIndex))"/>
</div>
</CellDisplayTemplate>
<CellEditTemplate>
<div class="grid-cell-align-center">
<DxButton Enabled="false"
CssClass="grid-disabled-button"
IconCssClass="grid-icon grid-icon-delete"
aria-label="Delete"
RenderStyle="ButtonRenderStyle.Link"/>
</div>
</CellEditTemplate>
</DxGridCommandColumn>
</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 more information.