Example T1106451
Visible to All Users

Grid for Blazor - How to delete selected rows

This example demonstrates how to delete selected rows from the DxGrid when a user clicks a DxButton.

Blazor DxGrid delete selected rows

The selection column allows users to select one or multiple rows depending on the SelectionMode property value. To create this column, declare a DxGridSelectionColumn object in the Columns template.

Implement two-way binding for the SelectedDataItems property to access data items that correspond to selected rows. Add a Delete selected rows button to the page and delete the selected data items when a user clicks this button.

Files to Look At

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

DeleteSelectedRows/Pages/Index.razor
Razor
@page "/" @using DeleteSelectedRows.Data @inject WeatherForecastService ForecastService @if (forecasts == null) { <p><em>Loading...</em></p> } else { <DxGrid @ref="myGrid" Data="@forecasts" CssClass="mw-1100" @bind-SelectedDataItems="@selectedDataItems" KeyFieldName="ID"> <Columns> <DxGridSelectionColumn /> <DxGridDataColumn Caption="Date" FieldName="Date" /> <DxGridDataColumn Caption="Temperature (F)" FieldName="TemperatureF" /> <DxGridDataColumn Caption="Temperature (C)" FieldName="TemperatureC" /> <DxGridDataColumn Caption="Summary" FieldName="Summary" /> </Columns> </DxGrid> <DxButton Text="Delete selected rows" Click="@OnClick"/> } @code { IGrid myGrid { get; set; } List<WeatherForecast> forecasts; IReadOnlyList<object> selectedDataItems { get; set; } protected override async Task OnInitializedAsync() { forecasts = await ForecastService.GetForecastAsync(DateTime.Now); } void OnClick(MouseEventArgs args) { if (selectedDataItems != null) { foreach(WeatherForecast row in selectedDataItems) forecasts.Remove(row); selectedDataItems = null; myGrid.Reload(); }; } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.