# Customizing the Grid Pager's DropDown

## Environment

| Property | Value                           |
| -------- | ------------------------------- |
| Product  | Telerik UI for ASP.NET MVC Grid |
| Version  | 2022.2.621                      |

## Description

I would like to customize the pagination drop-down in the Telerik UI for ASP.NET MVC Grid Grid footer to load all pages by default. How can I achieve this?

## Solution

To customize the pagination drop-down in the Telerik UI for ASP.NET MVC Grid Grid footer to load all pages by default, follow these steps:

1. Hide the default pager by adding the following CSS code:

```css
.k-grid-pager {
    display: none;
}
```

2. Implement a custom div element that will serve as the custom pager. For example:

```html
<div id="customPager"></div>
```

3. In the [`document.ready`](https://docs.telerik.com/kendo-ui/api/ui/grid/configuration/datasource) scope, retrieve the [`dataSource`](https://docs.telerik.com/kendo-ui/api/ui/grid/configuration/datasource) instance of the Telerik UI for ASP.NET MVC Grid Grid.

4. Handle the [`dataBound`](https://docs.telerik.com/kendo-ui/api/ui/grid/events/databound) Event of the Grid.

5. In the Event handler, Use the [`totalPages`](https://docs.telerik.com/kendo-ui/api/data/datasource/methods/totalpages) method of the `dataSource` to get the page count of the Grid.

6. Implement a DropDownList using the custom div element from step 2, with items ranging from 1 to the page count obtained in step 4.

7. Attach a [`change`](https://docs.telerik.com/kendo-ui/api/ui/dropdownlist/events/change) event handler to the DropDownList.

8. In the event handler, retrieve the current value of the DropDownList and set it as the current page of the Grid using the [`page`](https://docs.telerik.com/kendo-ui/api/data/datasource/methods/page) method of the `dataSource`.

Here is an example implementation:

```html

<div id="customPager"></div>

<style>
    .k-grid-pager {
        display: none;
    }
</style>

<script>
$(document).ready(function () {
    var grid = $("#grid").data("kendoGrid");

    // Attach an event handler to the dataBound event
    grid.bind("dataBound", function(e) {
        var pages = e.sender.dataSource.totalPages();
        var ddlData = [];

        for (var i = 1; i <= pages; i++) {
            ddlData.push(i);
        }

        // Check if the dropdown is already initialized to avoid re-initializing
        var customPager = $("#customPager").data("kendoDropDownList");
        if (!customPager) {
            $("#customPager").kendoDropDownList({
                dataSource: ddlData,
                change: onChange
            });
        } else {
            // If already initialized, just update its data
            customPager.setDataSource(ddlData);
            customPager.refresh();
        }
    });
});

function onChange() {
    var ddl = this;
    var currPage = ddl.value();
    var grid = $("#grid").data("kendoGrid");
    grid.dataSource.page(currPage);
}
</script>
```

## REPL examples

* [HtmlHelper](https://netcorerepl.telerik.com/GekHvdFq26Yj5vdj54)
* [TagHelper](https://netcorerepl.telerik.com/cekRPHlK28SgNOy332)

## 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 REPL: Change the Grid Pager to a Slider](https://netcorerepl.telerik.com/cnOGGPlA21RzEjkG12)
* [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)
