Skip to content

Commit 51d8515

Browse files
dimodiDimo Dimov
andauthored
docs: Document Pager InputType and PageSizes (#404)
* docs: Document Pager InputType and PageSizes * docs: Apply review comments - add anchors, remove wrong version note Co-authored-by: Dimo Dimov <[email protected]>
1 parent 54e56ad commit 51d8515

File tree

2 files changed

+59
-18
lines changed

2 files changed

+59
-18
lines changed

components/pager/events.md

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,23 @@ position: 20
1212

1313
This article explains the events available in the Telerik Pager for Blazor:
1414

15+
* [PageChanged](#pagechanged) - fires when the user navigates to another page
16+
* [PageSizeChanged](#pagesizechanged) - fires when the user selects a different page size
17+
1518
## PageChanged
1619

17-
The `PageChanged` event fires a new page is selected. You can use it to implement [load on demand]({%slug pager-overview%}#load-on-demand)
20+
The `PageChanged` event fires when a new page is selected. You can use it to implement [load on demand]({%slug pager-overview%}#load-on-demand).
21+
22+
Make sure to update the current page index when using the event.
1823

1924
>caption Handle PageChanged
2025
2126
````CSHTML
22-
@* Make sure to update the current page index when using the event *@
23-
2427
<TelerikPager Total="@TotalItems"
2528
ButtonCount="@ButtonCount"
2629
PageSize="@ItemsOnPage"
2730
Page="@CurrentPage"
28-
PageChanged="@( (int page) => PageChangedHandler(page) )">
29-
31+
PageChanged="@PageChangedHandler">
3032
</TelerikPager>
3133
3234
<div class="text-info">@Result</div>
@@ -36,19 +38,52 @@ The `PageChanged` event fires a new page is selected. You can use it to implemen
3638
public int ButtonCount { get; set; } = 4;
3739
public int ItemsOnPage { get; set; } = 10;
3840
public int CurrentPage { get; set; } = 2;
39-
public string Result { get; set; } = String.Empty;
41+
public string Result { get; set; }
4042
41-
void PageChangedHandler(int page)
43+
void PageChangedHandler(int newPage)
4244
{
43-
CurrentPage = page;
44-
Result = $"Current page: {page}";
45+
CurrentPage = newPage;
46+
Result = $"Current page: {newPage}";
4547
}
4648
}
4749
````
4850
>caption The result from the code snippet above
4951
5052
![config of the pager with one-way binding](images/pager-data-binding.gif)
5153

54+
## PageSizeChanged
55+
56+
The `PageSizeChanged` event fires when the user changes the page size via the pager DropDownList. The existence of this event also ensures that the `PageSize` attribute supports two-way binding.
57+
58+
If the user selects the "All" option from the page size DropDownList, the `PageSizeChanged` event will receive the total item count as an argument.
59+
60+
Make sure to update the current page size when using the event.
61+
62+
>caption Handle PageSizeChanged
63+
64+
````CSHTML
65+
<TelerikPager Total="@TotalItems"
66+
Page="@CurrentPage"
67+
PageSize="@ItemsOnPage"
68+
PageSizeChanged="@PageSizeChangedHandler">
69+
</TelerikPager>
70+
71+
<div class="text-info">@Result</div>
72+
73+
@code {
74+
public int TotalItems { get; set; } = 80;
75+
public int ItemsOnPage { get; set; } = 10;
76+
public int CurrentPage { get; set; } = 2;
77+
public string Result { get; set; }
78+
79+
void PageSizeChangedHandler(int newPageSize)
80+
{
81+
ItemsOnPage = newPageSize;
82+
Result = $"Current page size: {newPageSize}";
83+
}
84+
}
85+
````
86+
5287
## See Also
5388

5489
* [Pager Overview]({%slug pager-overview%})

components/pager/overview.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ The Pager provides the UI for the user to change the page. To the developer, it
8383

8484
## Features
8585

86+
* `Total` - `int` - Represents the total count of items in the pager. **Required.**
87+
* `ButtonCount` - `int` - The maximum number of page buttons that will be visible. To take effect, `ButtonCount` must be smaller than the page count (`ButtonCount < Total / PageSize`).
88+
* `Page` - `int` - Represents the current page of the pager. The first page has an index of `1`. Supports two-way data binding. If no value is provided, the parameter will default to the first page (1), but you should always use this parameter value in order to successfully use the component. If you don't use two-way binding and you don't update the value of the parameter after the user action, the pager UI will not reflect the change and will revert to the previous value (page index).
89+
* `PageSize` - `int` - The number of items to display on a page.
90+
* `PageSizes` - `List<int?>` - Allows users to change the page size via a DropDownList. The attribute configures the DropDownList options. A `null` item in the `PageSizes` `List` will render an "All" option. By default, the Pager DropDownList is not displayed. You can also set `PageSizes` to `null` programmatically to remove the DropDownList at any time.
91+
* `InputType` - `PagerInputType` - Determines if the pager will show numeric buttons to go to a specific page, or a textbox to type the page index. The arrow buttons are always visible. The `PagerInputType` enum accepts values `Buttons` (default) or `Input`. When `Input` is used, the page index will change when the textbox is blurred, or when the user hits Enter. This is to avoid unintentional data requests.
8692
* `Class` - The CSS class that will be rendered on the main wrapping element of the Pager.
87-
* `Total` - `int - Represents the total count of items in the pager. Required.
88-
* `ButtonCount` - `int` - The maximum number of page buttons that will be visible. To take effect the `ButtonCount` must be smaller than the pages count (`ButtonCount < Total / PageSize`).
89-
* `Page` - `int` - Represents the current page of the pager. The first page has an index of `1`. Supports two-way data binding. If no value is provided the parameter will default to the first page (1), but you should always use this parameter value in order to successfully use the component. If you don't use two-way binding and you don't update the value of the parameter after the user action, the pager UI will not reflect the change and will revert to the previous value (page index).
90-
* `PageSize` - `int` - The number of items to be presented on a page.
9193

9294
## Examples
9395

@@ -115,14 +117,18 @@ You can avoid loading all the data at once, as this can be a costly operation. I
115117
</div>
116118
}
117119
118-
<TelerikPager Total="@TotalGames" PageSize="@PageSize" Page="@CurrPage"
119-
PageChanged="@( (int page) => PageChangedHandler(page) )">
120+
<TelerikPager Total="@TotalGames"
121+
Page="@CurrPage"
122+
PageChanged="@PageChangedHandler"
123+
PageSize="@PageSize"
124+
PageSizes="@GamesPerPage">
120125
</TelerikPager>
121126
122127
@code {
123128
int TotalGames { get; set; }
124-
int CurrPage { get; set; } = 1; // the page indexes are 1-based
125-
int PageSize { get; set; } = 4;
129+
int CurrPage { get; set; } = 1; // page index is 1-based
130+
int PageSize { get; set; } = 5;
131+
public List<int?> GamesPerPage = new List<int?> { 5, 10, 20, null };
126132
127133
List<Game> PagedDataToRender { get; set; }
128134
@@ -144,7 +150,7 @@ You can avoid loading all the data at once, as this can be a costly operation. I
144150
}
145151
146152
// simulate a service below
147-
private List<Game> _allData { get; set; } = Enumerable.Range(1, 500).Select(x => new Game
153+
private List<Game> _allData { get; set; } = Enumerable.Range(1, 100).Select(x => new Game
148154
{
149155
GameName = $"Game {x}",
150156
GameId = x,

0 commit comments

Comments
 (0)