DxDataGrid<T>.InitNewRow Event

Enables you to initialize added data rows.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v21.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

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 MyApp.Data.WeatherForecastService ForecastService
@using MyApp.Data

<DxDataGrid DataAsync="@ForecastService.GetForecastAsync" 
            RowInsertingAsync="@OnRowInserting"
            InitNewRow="@OnInitNewRow">
    <DxDataGridCommandColumn />
    <DxDataGridDateEditColumn Field=@nameof(WeatherForecast.Date) />
    <DxDataGridSpinEditColumn Field="@nameof(WeatherForecast.TemperatureC)" 
                              Caption="@("Temp. (\x2103)")" />
    <DxDataGridColumn Field=@nameof(WeatherForecast.TemperatureF) Caption="Temp. (F)" />
</DxDataGrid>

@code {
    async Task OnRowInserting(IDictionary<string, object> newValue) {
        await ForecastService.Insert(newValue);
    }

    Task OnInitNewRow(Dictionary<string, object> values) {
        values.Add("Date", DateTime.Now);
        values.Add("TemperatureC", 13);
        return Task.CompletedTask;
    }
}

Online Demo

Data Grid - Column Types

See Also