Skip to main content

DxDataGrid<T>.InitNewRow Event

Enables you to initialize added data rows.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v22.1.dll

Declaration

[Parameter]
public Func<Dictionary<string, object>, Task> InitNewRow { get; set; }

Parameters

Type Description
Dictionary<String, Object>

A dictionary that lists column names and column values.

Remarks

Important

The Data Grid was moved to maintenance support mode. No new features/capabilities will be added to this component. We recommend that you migrate to the Grid component.

The InitNewRow event is raised when a user clicks the New button in a command column. Handle this event to display predefined values in new rows. Use the event handler’s parameter to add pairs of column names and column values.

@inject NwindDataService NwindDataService

<DxDataGrid Data="@Data"
            RowInsertingAsync="@OnRowInsertingAsync"
            InitNewRow="@OnInitNewRowAsync"
            ShowPager="false"
            KeyFieldName="@nameof(Employee.EmployeeId)"
            EditMode="@CurrentEditMode">
    <DxDataGridCommandColumn Width="120px" />
    <DxDataGridColumn Field="@nameof(Employee.FirstName)" />
    <DxDataGridColumn Field="@nameof(Employee.LastName)" />
    <DxDataGridColumn Field="@nameof(Employee.Title)" />
    <DxDataGridColumn Field="@nameof(Employee.TitleOfCourtesy)" Width="150px" />
    <DxDataGridDateEditColumn Field="@nameof(Employee.BirthDate)" Width="150px" />
    <DxDataGridDateEditColumn Field="@nameof(Employee.HireDate)" Width="150px" />
</DxDataGrid>

@code {
    IEnumerable<Employee> Data { get; set; }
    async Task OnRowInsertingAsync(IDictionary<string, object> newValues) {
        await NwindDataService.InsertEmployeeAsync(newValues);
        Data = await NwindDataService.GetEmployeesEditableAsync();
        StateHasChanged();
    }
    async Task OnInitNewRowAsync(Dictionary<string, object> values) {
        values.Add(nameof(Employee.FirstName), "John");
        values.Add(nameof(Employee.LastName), "Doe");
        await Task.CompletedTask;
    }
}

Run Demo: Data Grid - Column Types

See Also