DxDataGrid<T>.RowUpdating Event

Occurs when a user updates a data row.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v21.1.dll

Declaration

[Parameter]
public Action<T, Dictionary<string, object>> RowUpdating { get; set; }

Parameters

Type Description
T

A data item type that is passed to a delegate method as a parameter.

Dictionary<String, Object>

A collection of new row values.

Remarks

When users click the Edit button in a command column, the grid displays the Edit Form where you can change a row’s data. To post the changes to the Data Grid’s data source or discard these values, handle the RowUpdating event.

To control the visibility of the Edit command button, use the EditButtonVisible property.

@using System.Collections.ObjectModel

<DxDataGrid Data="@weatherForecasts"
            RowUpdating="@((updatingDataItem, newValues) => OnRowUpdating(updatingDataItem, newValues))">
    <DxDataGridCommandColumn />
    <DxDataGridDateEditColumn Field="@nameof(WeatherForecast.Date)" />
    <DxDataGridSpinEditColumn Field="@nameof(WeatherForecast.TemperatureC)" />
    <DxDataGridColumn Field="@nameof(WeatherForecast.CloudCover)" />
    <DxDataGridCheckBoxColumn Field="@nameof(WeatherForecast.Precipitation)" />
</DxDataGrid>

@code {
    public class WeatherForecast {
        public DateTime Date { get; set; }
        public int TemperatureC { get; set; }            
        public string CloudCover { get; set; }
        public bool Precipitation { get; set; }
    }

    static readonly Random random = new Random();
    readonly ObservableCollection<WeatherForecast> weatherForecasts = new ObservableCollection<WeatherForecast>();

    protected override void OnInitialized() {
        String[] CloudCover = {"Sunny", "Partly cloudy", "Cloudy", "Storm"};

        foreach (var date in Enumerable.Range(1, 30).Select(i => DateTime.Now.Date.AddDays(i))) {
            weatherForecasts.Add(new WeatherForecast() {
                Date = date,
                TemperatureC = random.Next(10, 20),
                Precipitation = Convert.ToBoolean(random.Next(0, 2)),
                CloudCover = CloudCover[random.Next(0,CloudCover.Length)]
            });
        }
    }

    static WeatherForecast UpdateItem(WeatherForecast item, Dictionary<string, object> itemProperties) {
        foreach (var field in itemProperties.Keys) {
            switch (field) {
                case "Date":
                    item.Date = (DateTime)itemProperties[nameof(WeatherForecast.Date)];
                    break;
                case "TemperatureC":
                    item.TemperatureC = (int)itemProperties[nameof(WeatherForecast.TemperatureC)];
                    break;
                case "Precipitation":
                    item.Precipitation = (bool)itemProperties[nameof(WeatherForecast.Precipitation)];
                    break;
            }
        }
        return item;
    }

    void OnRowUpdating(WeatherForecast item, Dictionary<string, object> itemProperties) {
        UpdateItem(item, itemProperties);
    }
}

Online Demo

Data Grid - Column Types

See Also