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

Changing the Grid Pager to a Slider

Environment

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

Description

How can I change the default pager of the Telerik UI for ASP.NET Core Grid to a slider?

Solution

To achieve the desired result:

  1. Handle the DataBound event in order to remove the default pager buttons.
  2. To substitute the default pager, create a Kendo UI Slider widget instance in its place.
  3. To prevent the Kendo UI Slider from creating numerous times, declare a flag variable.
  4. Change the page of the Grid DataSource by handling the Change event of the Slider.

When you apply this approach, the page method of the Grid's DataSource will not fire.

Index.cshtml
    @(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);
            columns.Command(command => { command.Edit(); command.Destroy(); }).Width(200);
        })
        .Events(events => events.DataBound("onDataBound"))
        .ToolBar(toolbar => toolbar.Create())
        .Editable(editable => editable.Mode(GridEditMode.InLine))
        .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 the complete implementation of the suggested approach, refer to the Telerik REPL example on changing the Grid pager to a slider.

More ASP.NET Core Grid Resources

See Also