# Placing Edit or Update Buttons to Grid Toolbar

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Grid</td>
 </tr>
 <tr>
  <td>Progress Telerik UI for ASP.NET MVC version</td>
  <td>Created with the 2023.3.1114 version</td>
 </tr>
</table>

## Description

How can I limit the number of columns in the Grid and move the **Edit** and **Update** buttons to the toolbar to save space when using the Telerik UI for ASP.NET MVC Grid?

## Solution

To achieve the desired result:

1. Enable selection for the Grid.
2. Define a toolbar template that will hold all custom buttons used for editing.
3. Handle the click event for the buttons to enter/exit edit mode.

```Razor Index.cshtml

    <script type="text/x-kendo-template" id="template"> // ToolBar Template
        <div class="editBtnContainer">
             <button type="button" class="k-button  k-grid-custom">Edit</button>

        </div>
        <div class="updateCancelContainer">
                <a role="button" class="k-button    k-grid-save-command" href="\\#">
            <span class="k-icon k-i-check k-button-icon"></span>Update</a>
            <a role="button" class="k-button    k-grid-cancel-command" href="\\#">
            <span class="k-icon k-i-cancel k-button-icon"></span>Cancel</a>
        </div>
    </script>


    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(p => p.ProductName);
            columns.Bound(p => p.UnitPrice).Width(100);
            columns.Bound(p => p.UnitsInStock).Width(100);
            columns.Bound(p => p.Discontinued).Width(100);
        })
        .ToolBar(toolbar => toolbar.ClientTemplateId("template"))
        .Editable(editable => editable.Mode(GridEditMode.InLine))
        .Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
        .Pageable()
        .Sortable()
        .Scrollable()
        .HtmlAttributes(new { style = "height:430px;" })
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(20)
            .Model(model => model.Id(p => p.ProductID))
            .Create(update => update.Action("EditingInline_Create", "Grid"))
            .Read(read => read.Action("EditingInline_Read", "Grid"))
            .Update(update => update.Action("EditingInline_Update", "Grid"))
            .Destroy(update => update.Action("EditingInline_Destroy", "Grid"))
        )
    )

```

```JS script.js
    $(document).ready(function(){

        $(".k-grid-custom.k-button").on("click", function (e) {
            e.preventDefault();
            var grid = $("#grid").getKendoGrid();
            var selectedRow = grid.select()[0];
            if (selectedRow) {
                grid.editRow(selectedRow);

                $(".editBtnContainer, .updateCancelContainer").toggle();
            }
        });

        $(".k-grid-save-command").on("click", function (e) {
            e.preventDefault();
            var grid = $("#grid").getKendoGrid();
            grid.dataSource.sync();
            $(".editBtnContainer, .updateCancelContainer").toggle();
        });

        $(".k-grid-cancel-command").on("click", function (e) {
            e.preventDefault();
            var grid = $("#grid").getKendoGrid();
            grid.cancelChanges();
            $(".editBtnContainer, .updateCancelContainer").toggle();
        });

    })
```

```C# Styles.css
    .updateCancelContainer {
        display: none;
    }
```

For a complete implementation of the suggested approach, refer to the following Telerik REPL  example :

* [Telerik REPL (HtmlHelper)](https://netcorerepl.telerik.com/cyabaXYA35fEE7He32)

## 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

* [Telerik REPL: Placing Edit or Update Buttons to Grid Toolbar (HtmlHelper)](https://netcorerepl.telerik.com/cyabaXYA35fEE7He32)

* [Server-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/grid)

* [Client-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/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)
