New to Kendo UI for jQuery? Start a free 30-day trial
Change Grid Pager to Slider
Updated over 6 months ago
Environment
| Product | Progress® Kendo UI® Grid for jQuery | 
| Operating System | Windows 10 64bit | 
| Preferred Language | JavaScript | 
Description
How can I change the default pager of the Kendo UI Grid to a slider?
Solution
- Remove the default pager buttons on the first dataBoundevent.
- Create a Kendo UI Slider in their place.
- Change the page of the Grid DataSource on the changeevent of the Slider.
When you apply this approach, the
pagemethod of the Grid does not fire.
<div id="grid"></div>
<script>
  var sliderCreated = false;  
  $("#grid").kendoGrid({
    columns: [
      { field: "productName" },
      { field: "category" }
    ],
    dataSource: [
      { productName: "Tea", category: "Beverages" },
      { productName: "Coffee", category: "Beverages" },
      { productName: "Ham", category: "Food" },
      { productName: "Bread", category: "Food" },
      { productName: "Cheese", category: "Food" },
      { productName: "Milk", category: "Beverages" }
    ],
    pageable: {
      pageSize: 2
    },
    dataBound: onDataBound
  });
  function onChange(e){
    var grid = $("#grid").data("kendoGrid");
    grid.dataSource.page(e.value)
  };
  function onDataBound(e){
    if(!sliderCreated){
      sliderCreated = true;
      var max = e.sender.dataSource.totalPages();
      $(".k-grid-pager").find("a, ul").each(function(i) {
        $(this).remove()
      });
      $(".k-grid-pager").prepend($("<input id='slider' />"));
      $("#slider").kendoSlider({
        min: 1,
        max: max,
        tickPlacement: "none",
        change: onChange
      });
    }
  };
</script>
<style>
  #grid .k-slider-horizontal{
    margin: 0.4em 0.4em 0 0.4em;
  }  
</style>