|
1 | 1 | --- |
2 | | -title: Paging |
| 2 | +title: Pager |
3 | 3 | page_title: Pager for Blazor Overview |
4 | | -description: Enable and configure paging in Grid for Blazor |
| 4 | +description: Add a page navigation to Blazor application |
5 | 5 | slug: components-pager-overview |
6 | 6 | tags: telerik,blazor,pager,paging |
7 | 7 | published: True |
8 | 8 | position: 20 |
9 | 9 | --- |
10 | 10 |
|
11 | | -# Grid Paging |
| 11 | +# Pager Overview |
12 | 12 |
|
13 | | -The Grid component offers support for paging. |
| 13 | +The `Pager` component will enable you to add page navigation in your Blazor application. It follows the design patter of our components but as standalone one can be used outside of Grid. |
14 | 14 |
|
15 | | -To enable paging, set its `Pageable` property to `true`. |
| 15 | +To use Telerik Pager component for Blazor: |
| 16 | +1. Add the `TelerikPager` tag |
| 17 | +1. (optional) Populate it's `Total` parameter |
| 18 | +1. (optional) Set it's `ButtonCount` parameter |
| 19 | +1. (optional) Set the `PageChanged` parameter |
| 20 | +1. (optional) Set `Page` or `@bind-Page` (one and two-way data binding) |
| 21 | +1. (optional) Set a `PageSize` |
16 | 22 |
|
17 | | -You can control the number of records per page through the `PageSize` property. |
18 | | - |
19 | | -You can set the current page of the grid through its integer `Page` property. |
20 | | - |
21 | | ->caption Enable paging in Telerik Grid |
| 23 | +>caption Basic setup of Pager component in your application |
22 | 24 |
|
23 | 25 | ````CSHTML |
24 | | -Enable paging and start on the second page. |
| 26 | +@*Basic Pager configuration.*@ |
| 27 | +
|
| 28 | +<TelerikPager Total="TotalItems" |
| 29 | + ButtonCount="ButtonCount" |
| 30 | + PageSize="ItemsOnPage" |
| 31 | + @bind-Page="CurrentPage"> |
25 | 32 |
|
26 | | -<TelerikGrid Data="@MyData" Pageable="true" PageSize="15" Page="2" Height="500px"> |
27 | | - <GridColumns> |
28 | | - <GridColumn Field="ID"></GridColumn> |
29 | | - <GridColumn Field="TheName" Title="Employee Name"></GridColumn> |
30 | | - </GridColumns> |
31 | | -</TelerikGrid> |
| 33 | +</TelerikPager> |
32 | 34 |
|
33 | 35 | @code { |
34 | | - public IEnumerable<object> MyData = Enumerable.Range(1, 50).Select(x => new { ID = x, TheName = "name " + x }); |
| 36 | + public int TotalItems { get; set; } = 80; |
| 37 | + public int ButtonCount { get; set; } = 4; |
| 38 | + public int ItemsOnPage { get; set; } = 10; |
| 39 | + public int CurrentPage { get; set; } = 2; |
35 | 40 | } |
36 | 41 | ```` |
37 | 42 |
|
38 | 43 | >caption The result from the code snippet above |
39 | 44 |
|
40 | | - |
| 45 | + |
| 46 | + |
| 47 | +## Features |
| 48 | +* `Class` - The CSS class that will be rendered on the main wrapping element of the Pager. |
| 49 | +* `Total` - **int** - Represents the total count of items in the pager. |
| 50 | +* `ButtonCount` - **int** - The number of pages to be visible. To take effect the `ButtonCount` must be **less** than the pages count (ButtonCount < Total / number of items on the page) |
| 51 | +* `Page` and `@bind-Page` - **int** - Represents the current page of the pager. Those parameters are respectively for one and two-way data binding. If no `Page` or `@bind-Page` are provided they will default to the first page (1). |
| 52 | +* `PageChanged` - Fires when a new page is selected (used in one-way data binding). |
| 53 | +* `PageSize` - **int** - The number of items to be presented on a pages. |
| 54 | + |
| 55 | +## Examples |
| 56 | + |
| 57 | +>caption Observe the behavior of the Pager with one-way data binding |
| 58 | +
|
| 59 | +````CSHTML |
| 60 | +@*This example showcases the usage of Page and PageChanged in conjunction*@ |
| 61 | +
|
| 62 | +<TelerikPager Total="TotalItems" |
| 63 | + ButtonCount="ButtonCount" |
| 64 | + PageSize="ItemsOnPage" |
| 65 | + Page="CurrentPage" |
| 66 | + PageChanged="@( (int page) => PageChangedHandler(page) )"> |
41 | 67 |
|
42 | | ->tip You can bind the values of those properties to variables in the `@code {}` section. If you want to bind the page index to a variable, you must use the `@bind-Page="@MyPageIndexVariable"` syntax. |
| 68 | +</TelerikPager> |
43 | 69 |
|
44 | | -Here is one way to implement a page size choice that puts all records on one page. |
| 70 | +<div class="text-info">@Result</div> |
45 | 71 |
|
46 | | ->caption Bind Page Size to a variable |
| 72 | +@code { |
| 73 | + public int TotalItems { get; set; } = 80; |
| 74 | + public int ButtonCount { get; set; } = 4; |
| 75 | + public int ItemsOnPage { get; set; } = 10; |
| 76 | + public int CurrentPage { get; set; } = 2; |
| 77 | + public string Result { get; set; } = String.Empty; |
| 78 | +
|
| 79 | + void PageChangedHandler(int page) |
| 80 | + { |
| 81 | + CurrentPage = page; |
| 82 | + Result = $"Current page: {page}"; |
| 83 | + } |
| 84 | +} |
| 85 | +```` |
| 86 | +>caption The result from the code snippet above |
| 87 | +
|
| 88 | + |
| 89 | + |
| 90 | +>caption Observe the behavior of the Pager with two-way data binding |
47 | 91 |
|
48 | 92 | ````CSHTML |
49 | | -Dynamic page size change |
50 | | -
|
51 | | -<select @onchange=@ChangePageSize> |
52 | | - @for (int i = 1; i < 4; i++) |
53 | | - { |
54 | | - <option value=@(i*10)>@(i * 10)</option> |
55 | | - } |
56 | | - <option value="all" selected>all</option> |
57 | | -</select> |
58 | | -
|
59 | | -<TelerikGrid Data="@MyData" Pageable="true" PageSize="@PageSize"> |
60 | | - <GridColumns> |
61 | | - <GridColumn Field="ID"></GridColumn> |
62 | | - <GridColumn Field="TheName" Title="Employee Name"></GridColumn> |
63 | | - </GridColumns> |
64 | | -</TelerikGrid> |
| 93 | +@*This example showcases the usage of Page and PageChanged in conjunction*@ |
| 94 | +
|
| 95 | +<TelerikPager Total="TotalItems" |
| 96 | + ButtonCount="ButtonCount" |
| 97 | + PageSize="ItemsOnPage" |
| 98 | + @bind-Page="CurrentPage"> |
65 | 99 |
|
| 100 | +</TelerikPager> |
| 101 | +<div class="text-info">Current page: @CurrentPage</div> |
66 | 102 | @code { |
67 | | - public IEnumerable<object> MyData = Enumerable.Range(1, 50).Select(x => new { ID = x, TheName = "name " + x }); |
68 | | -
|
69 | | - protected int PageSize { get; set; } |
70 | | -
|
71 | | - protected void ChangePageSize(ChangeEventArgs e) |
72 | | - { |
73 | | - if (e.Value.ToString().ToLowerInvariant() == "all") |
74 | | - { |
75 | | - PageSize = MyData.Count(); |
76 | | - } |
77 | | - else |
78 | | - { |
79 | | - PageSize = int.Parse(e.Value.ToString()); |
80 | | - } |
81 | | - } |
| 103 | + public int TotalItems { get; set; } = 80; |
| 104 | + public int ButtonCount { get; set; } = 4; |
| 105 | + public int ItemsOnPage { get; set; } = 10; |
| 106 | + public int CurrentPage { get; set; } = 2; |
82 | 107 | } |
83 | 108 | ```` |
| 109 | +>caption The result from the code snippet above |
| 110 | +
|
| 111 | + |
84 | 112 |
|
85 | 113 | ## See Also |
86 | 114 |
|
87 | | - * [Live Demo: Grid Paging](https://demos.telerik.com/blazor-ui/grid/paging) |
| 115 | +* [Live Demo: Pager Overview](https://demos.telerik.com/blazor-ui/pager/overview) |
| 116 | +* [Live Demo: Pager Integration](https://demos.telerik.com/blazor-ui/pager/integration) |
| 117 | +* [Live Demo: Pager Localization](https://demos.telerik.com/blazor-ui/pager/localization) |
| 118 | +* [Live Demo: Pager Keyboard Navigation](https://demos.telerik.com/blazor-ui/pager/keyboard-navigation) |
0 commit comments