# Removing Previously Selected Items in the Grid

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Grid for Progress® Telerik® UI for ASP.NET MVC</td>
 </tr>
</table>

## Description

I have a Grid where custom buttons are implemented per row. When a custom button in a row is clicked, the row should be marked as deleted, but the removal should be applied when clicking a custom **Delete** button outside of the Grid.

## Solution

To achieve the desired behavior, use the following approach:

1. Add a custom Command button for every row.
2. Handle the click of the custom button.
3. The button stands for a row, so when clicked, add it to a global scope variable (array).
4. You can add some styles to the clicked row—this allows you to show that this row will be removed.
5. For the removal, add a new custom button outside of the Grid or in its Toolbar.
6. In the [`Click`](https://docs.telerik.com/kendo-ui/api/ui/button/events/click) event handler of the button from step 5, remove all the rows saved in the global scope variable. You can achieve this with the help of the [`removeRow`](https://docs.telerik.com/kendo-ui/api/ui/grid/methods/removerow) method.

The following example represents the steps described above.

```
// In the Grid, add the custom button.
columns.Command(command => command.Custom("DeleteRow").Click("deleteRow")).Width(180);

// The click of a DeleteRow button (and the global scope variable)
    var rowsToDelete = [];

    function deleteRow(e) {
        var currRow = $(e.currentTarget).closest('tr')[0];

        //Adding a custom style for the rows that will be removed
        $(currRow).css("background-color", "red");

        rowsToDelete.push(currRow);
    }

// The Click Event handler of the button in step 5
    var rowsToDelete = [];

    function deleteRow(e) {
        var currRow = $(e.currentTarget).closest('tr')[0];

        //Adding a custom style for the rows that will be removed
        $(currRow).css("background-color", "red");

        rowsToDelete.push(currRow);
    }
```

## More ASP.NET MVC Grid Resources

* [ASP.NET MVC Grid Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/overview)

* [ASP.NET MVC Grid Demos](https://demos.telerik.com/aspnet-mvc/grid/index)

* [ASP.NET MVC Grid Product Page](https://www.telerik.com/aspnet-mvc/grid)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/grid)
* [Server-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/grid)
* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)
* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
