@@ -8,73 +8,99 @@ published: True
88position : 40
99---
1010
11-
1211# Pager Template
1312
14- The ` GridPagerTemplate ` allows you to modify the layout, content, and functionality of the Pager. To paginate the data, you can use any set of Blazor components and DOM elements instead of the default Grid [ Pager] ( slug:pager-overview ) .
15-
13+ The ` GridPagerTemplate ` allows you to modify the layout, content, and functionality of the Pager. To page the data, you can use any set of Blazor components and DOM elements instead of the default Grid [ Pager component] ( slug:pager-overview ) .
1614
1715> caption Using the Telerik UI for Blazor Slider to paginate the Grid data
1816
1917```` RAZOR
20- @* Telerik Blazor Grid with Pager Template *@
21- <TelerikGrid Data="@GridData"
18+ @using Telerik.DataSource
19+ @using Telerik.DataSource.Extensions
20+
21+ <TelerikGrid OnRead="@OnGridRead"
22+ TItem="@Product"
23+ FilterMode="GridFilterMode.FilterRow"
24+ Height="360px"
2225 Pageable="true"
23- @bind-Page="@CurrentPage"
24- PageSize="@PageSize">
26+ @bind-Page="@GridPage"
27+ PageSize="@GridPageSize"
28+ Sortable="true">
2529 <GridPagerTemplate>
26- <div style="padding:10px">
27- <TelerikSlider @bind-Value="@CurrentPage"
28- Width="100%"
29- Min="1"
30- Max="@Total">
31- </TelerikSlider>
30+ <div style="padding: var(--kendo-spacing-2); display: flex; justify-content: space-between; align-items: center;">
31+ @if (GridTotal > 0)
32+ {
33+ <TelerikSlider @bind-Value="@GridPage"
34+ Min="1"
35+ Max="@Convert.ToInt32(Math.Ceiling((decimal)GridTotal / (decimal)GridPageSize))"
36+ Width="50%">
37+ </TelerikSlider>
38+ }
39+ <div>
40+ Page @GridPage. Showing rows @GetVisibleRowRange() or @CurrentPageTotal of @GridTotal
41+ </div>
3242 </div>
3343 </GridPagerTemplate>
3444 <GridColumns>
35- <GridColumn Field="Name" Title="Product Name" />
36- <GridColumn Field="Price" DisplayFormat="{0:C2}" />
37- <GridColumn Field="@nameof(Product.Released)" DisplayFormat="{0:D}" />
38- <GridColumn Field="@nameof(Product.Discontinued)" />
45+ <GridColumn Field="@nameof(Product.Name)" />
46+ <GridColumn Field="@nameof(Product.Price)" DisplayFormat="{0:c2}" />
47+ <GridColumn Field="@nameof(Product.Quantity)" DisplayFormat="{0:n0}" />
3948 </GridColumns>
4049</TelerikGrid>
4150
4251@code {
43- private List<Product> GridData { get; set; }
52+ private List<Product> GridData { get; set; } = new();
4453
45- private int CurrentPage { get; set; } = 1;
54+ private int GridPage { get; set; } = 1;
55+ private int GridPageSize { get; set; } = 10;
4656
47- private int PageSize { get; set; } = 10;
57+ private int CurrentPageTotal { get; set; }
58+ private int GridTotal { get; set; }
4859
49- private int Total { get; set; } = 10;
60+ private string GetVisibleRowRange()
61+ {
62+ return $"{(GridPage - 1) * GridPageSize + 1} - {Math.Min(GridPage * GridPageSize, GridTotal)}";
63+ }
5064
51- protected override void OnInitialized( )
65+ private async Task OnGridRead(GridReadEventArgs args )
5266 {
53- GridData = new List<Product>( );
67+ DataSourceResult result = await GridData.ToDataSourceResultAsync(args.Request );
5468
55- var rnd = new Random();
69+ args.Data = result.Data;
70+ CurrentPageTotal = result.Data.Cast<Product>().Count();
5671
57- for (int i = 1; i <= 100; i++)
58- {
59- GridData.Add(new Product
60- {
61- Id = i,
62- Name = "Product name " + i,
63- Price = (decimal)(rnd.Next(1, 50) * 3.14),
64- Released = DateTime.Now.AddDays(-rnd.Next(1, 365)).AddYears(-rnd.Next(1, 10)).Date,
65- Discontinued = i % 5 == 0
66- });
72+ args.Total = result.Total;
73+ GridTotal = result.Total;
6774
68- }
75+ args.AggregateResults = result.AggregateResults;
76+ }
77+
78+ protected override void OnInitialized()
79+ {
80+ var rnd = Random.Shared;
6981
70- base.OnInitialized();
82+ for (int i = 1; i <= 47; i++)
83+ {
84+ GridData.Add(new Product()
85+ {
86+ Id = i,
87+ Name = $"Name {i} {(char)rnd.Next(65, 91)}{(char)rnd.Next(65, 91)}",
88+ Group = $"Group {i % 3 + 1}",
89+ Price = rnd.Next(1, 100) * 1.23m,
90+ Quantity = rnd.Next(0, 10000),
91+ Released = DateTime.Today.AddDays(-rnd.Next(60, 1000)),
92+ Discontinued = i % 4 == 0
93+ });
94+ }
7195 }
7296
7397 public class Product
7498 {
7599 public int Id { get; set; }
76- public string Name { get; set; }
100+ public string Name { get; set; } = string.Empty;
101+ public string Group { get; set; } = string.Empty;
77102 public decimal Price { get; set; }
103+ public int Quantity { get; set; }
78104 public DateTime Released { get; set; }
79105 public bool Discontinued { get; set; }
80106 }
@@ -84,5 +110,4 @@ The `GridPagerTemplate` allows you to modify the layout, content, and functional
84110## See Also
85111
86112 * [ Live Demo: Grid Templates] ( https://demos.telerik.com/blazor-ui/grid/templates )
87- * [ Blazor Grid] ( slug:grid-overview )
88-
113+ * [ Get Current Page of Grid Items and Total Count] ( slug:grid-kb-get-filtered-data )
0 commit comments