New to Telerik UI for ASP.NET CoreStart a free 30-day trial

Placing Edit or Update Buttons to Grid Toolbar

Environment

ProductTelerik UI for ASP.NET Core Grid
Progress Telerik UI for ASP.NET Core versionCreated with the 2023.3.1114 version

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 Core 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.
Index.cshtml

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

        </div>
        <div class="updateCancelContainer">
                <a role="button" class="k-button k-button-md k-rounded-md k-button-solid    k-button-solid-base 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-button-md k-rounded-md k-button-solid    k-button-solid-base 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"))
        )
    )

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

More ASP.NET Core Grid Resources

See Also