Introduction
This article tells you how to use the pager visibility in Kendo Grid with remote data. This is one of the key features in Kendo Grid, which is available from Kendo R3 2017 release.
Content
- Remote Data Source for Kendo Grid
- Building a Kendo Grid with remote datasource
- Pager Visibility in Kendo Grid
Remote Data Source for Kendo Grid
I am going to use the API response given below to construct my remote data source for Kendo Grid which was created in my previous article.
- API - http://github-ci-staging.azurewebsites.net/api/Technologies/TechnologiesLimitedList
- Type - GET.
Test the APIs using POSTMAN.
Figure 1
Build a Kendo Grid with remote datasource
Create a new HTML page. In my case, I named it KendoPaging.cshtml
KendoPaging.cshtml
- <!DOCTYPE html>
- <html>
- <head>
- <base href="http://demos.telerik.com/kendo-ui/sortable/integration-grid">
- <style>
- html {
- font-size: 14px;
- font-family: Arial, Helvetica, sans-serif;
- }
- </style>
- <title></title>
- <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.913/styles/kendo.common-material.min.css" />
- <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.913/styles/kendo.material.min.css" />
- <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.913/styles/kendo.material.mobile.min.css" />
-
- <script src="https://kendo.cdn.telerik.com/2017.3.913/js/jquery.min.js"></script>
- <script src="https://kendo.cdn.telerik.com/2017.3.913/js/kendo.all.min.js"></script>
-
-
- </head>
- <body>
-
-
- <div id="example">
- <div id="grid"></div>
-
- <script>
- $(document).ready(function() {
-
-
- var grid = $("#grid").kendoGrid({
- dataSource: {
- type: "json",
- transport: {
- read: "http://github-ci-staging.azurewebsites.net/api/Technologies/TechnologiesLimitedList"
-
- },
- schema: {
- model: {
- fields: {
- value: { type: "number" },
- text: { type: "string" },
-
- }
- }
- },
- pageSize: 20,
-
- },
-
- pageable: {
- refresh: true,
- pageSizes: [20, 40, 60, 80,100],
-
- },
- height: 500,
- columns: [
-
- { field: "value", title: "S No", width: "130px" },
- { field: "text", title: "Technology", width: "130px" },
-
- ]
- }).data("kendoGrid");
-
-
- });
- </script>
-
-
- </div>
-
-
- </body>
- </html>
From the above code, you can notice that the Kendo Grid is constructed based on our remote datasource which is formed from REST API.
Result
Figure 2
Pager Visibility in Kendo Grid
Pager Visibility attribute in a page-able property is used to make the pager visible or not, based on its requirement, just by changing the status of the attribute.
By default, the pager visibility will be true, which means that the pager is always visible in Grid even when the total amount of items in the datasource is less than a pageSize.
The Pager will be hidden when the total amount of items in the datasource is less than pageSize, by setting pager visibility as false.
Result
FIgure 3
So, by default, the pager alwaysVisible attribute is true .
Making alwaysVisible as false.
- <!DOCTYPE html>
- <html>
- <head>
- <base href="http://demos.telerik.com/kendo-ui/sortable/integration-grid">
- <style>
- html {
- font-size: 14px;
- font-family: Arial, Helvetica, sans-serif;
- }
- </style>
- <title></title>
- <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.913/styles/kendo.common-material.min.css" />
- <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.913/styles/kendo.material.min.css" />
- <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2017.3.913/styles/kendo.material.mobile.min.css" />
-
- <script src="https://kendo.cdn.telerik.com/2017.3.913/js/jquery.min.js"></script>
- <script src="https://kendo.cdn.telerik.com/2017.3.913/js/kendo.all.min.js"></script>
-
-
- </head>
- <body>
-
-
- <div id="example">
- <div id="grid"></div>
-
- <script>
- $(document).ready(function() {
-
-
- var grid = $("#grid").kendoGrid({
- dataSource: {
- type: "json",
- transport: {
- read: "http://github-ci-staging.azurewebsites.net/api/Technologies/TechnologiesLimitedList"
-
- },
- schema: {
- model: {
- fields: {
- value: { type: "number" },
- text: { type: "string" },
-
- }
- }
- },
- pageSize: 20,
-
- },
-
- pageable: {
- refresh: true,
- alwaysVisible:false,
- pageSizes: [20, 40, 60, 80,100],
-
- },
- height: 500,
- columns: [
-
- { field: "value", title: "S No", width: "130px" },
- { field: "text", title: "Technology", width: "130px" },
-
- ]
- }).data("kendoGrid");
-
-
- });
- </script>
-
-
- </div>
-
-
- </body>
- </html>
Result
Figure 4
From the above figure, you can notice that the pager is hidden once the total number of items in datasource is less than a pageSize.
Reference
https://docs.telerik.com/kendo-ui/api/javascript/ui/grid
I hope you have enjoyed this article. Your valuable feedback, questions, or comments about this article are always welcome.
Download the source code
here.