From 36a397712e80e279c3f12f497b325d81ed128434 Mon Sep 17 00:00:00 2001 From: Saleh Yusefnejad Date: Sat, 16 Nov 2024 21:56:50 +0330 Subject: [PATCH] feat(blazorui): add missing features to customize texts of paginator in BitDataGrid #9247 (#9248) --- .../Pagination/BitDataGridPaginationState.cs | 14 +- .../Pagination/BitDataGridPaginator.razor | 48 ++++- .../Pagination/BitDataGridPaginator.razor.cs | 41 +++- .../Extras/DataGrid/BitDataGridDemo.razor | 178 +++++++++--------- .../Extras/DataGrid/BitDataGridDemo.razor.cs | 142 +++++++++++++- 5 files changed, 311 insertions(+), 112 deletions(-) diff --git a/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/Pagination/BitDataGridPaginationState.cs b/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/Pagination/BitDataGridPaginationState.cs index 9a24839afb..05b66e352e 100644 --- a/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/Pagination/BitDataGridPaginationState.cs +++ b/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/Pagination/BitDataGridPaginationState.cs @@ -5,15 +5,20 @@ /// public class BitDataGridPaginationState { + /// + /// Gets the current zero-based page index. To set it, call . + /// + public int CurrentPageIndex { get; private set; } + /// /// Gets or sets the number of items on each page. /// public int ItemsPerPage { get; set; } = 10; /// - /// Gets the current zero-based page index. To set it, call . + /// Gets the zero-based index of the last page, if known. The value will be null until is known. /// - public int CurrentPageIndex { get; private set; } + public int? LastPageIndex => (TotalItemCount - 1) / ItemsPerPage; /// /// Gets the total number of items across all pages, if known. The value will be null until an @@ -21,11 +26,6 @@ public class BitDataGridPaginationState /// public int? TotalItemCount { get; private set; } - /// - /// Gets the zero-based index of the last page, if known. The value will be null until is known. - /// - public int? LastPageIndex => (TotalItemCount - 1) / ItemsPerPage; - /// /// An event that is raised when the total item count has changed. /// diff --git a/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/Pagination/BitDataGridPaginator.razor b/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/Pagination/BitDataGridPaginator.razor index 2ece139ac7..2fa1f8fef9 100644 --- a/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/Pagination/BitDataGridPaginator.razor +++ b/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/Pagination/BitDataGridPaginator.razor @@ -6,7 +6,11 @@
@if (SummaryTemplate is not null) { - @SummaryTemplate + @SummaryTemplate(Value) + } + else if (SummaryFormat is not null) + { + @SummaryFormat(Value) } else { @@ -14,14 +18,44 @@ }
} diff --git a/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/Pagination/BitDataGridPaginator.razor.cs b/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/Pagination/BitDataGridPaginator.razor.cs index 57f036b321..140c9a2847 100644 --- a/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/Pagination/BitDataGridPaginator.razor.cs +++ b/src/BlazorUI/Bit.BlazorUI.Extras/Components/DataGrid/Pagination/BitDataGridPaginator.razor.cs @@ -8,14 +8,49 @@ public partial class BitDataGridPaginator : IDisposable private readonly EventCallbackSubscriber _totalItemCountChanged; /// - /// Specifies the associated . This parameter is required. + /// The title of the go to first page button. /// - [Parameter, EditorRequired] public BitDataGridPaginationState Value { get; set; } = default!; + [Parameter] public string GoToFirstButtonTitle { get; set; } = "Go to first page"; + + /// + /// The title of the go to previous page button. + /// + [Parameter] public string GoToPrevButtonTitle { get; set; } = "Go to previous page"; + + /// + /// The title of the go to next page button. + /// + [Parameter] public string GoToNextButtonTitle { get; set; } = "Go to next page"; + + /// + /// The title of the go to last page button. + /// + [Parameter] public string GoToLastButtonTitle { get; set; } = "Go to last page"; + + /// + /// Optionally supplies a format for rendering the page count summary. + /// + [Parameter] public Func? SummaryFormat { get; set; } /// /// Optionally supplies a template for rendering the page count summary. /// - [Parameter] public RenderFragment? SummaryTemplate { get; set; } + [Parameter] public RenderFragment? SummaryTemplate { get; set; } + + /// + /// The optional custom format for the main text of the paginator in the middle of it. + /// + [Parameter] public Func? TextFormat { get; set; } + + /// + /// The optional custom template for the main text of the paginator in the middle of it. + /// + [Parameter] public RenderFragment? TextTemplate { get; set; } + + /// + /// Specifies the associated . This parameter is required. + /// + [Parameter, EditorRequired] public BitDataGridPaginationState Value { get; set; } = default!; /// /// Constructs an instance of . diff --git a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/DataGrid/BitDataGridDemo.razor b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/DataGrid/BitDataGridDemo.razor index 91912fc93a..1b5f0e72a2 100644 --- a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/DataGrid/BitDataGridDemo.razor +++ b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/DataGrid/BitDataGridDemo.razor @@ -3,8 +3,6 @@ @using Demo.Shared.Dtos.DataGridDemo @inherits AppComponentBase -@inject HttpClient HttpClient -@inject NavigationManager NavManager - - -
-
- - - - - - - - - - - -
- -
-
-
- - - -
-
- - - - - - - - @(context.Code) - - - - - - - - - -
- -
-
-
- - - -
- - - - - - - + + +
+
+ + + + + + + + + +
-
- -
- - + +
+
+
- - -
- - - - + + +
+
+ + + + + + + + @(context.Code) + + + + + + + +
-
- -
- - + + @(state.CurrentPageIndex + 1) / @(state.LastPageIndex + 1) + +
+
+
+ + + +
+ + + + + + + + +
+
+ +
+
+
+ + + +
+ + + + + +
+
+ +
+
+
diff --git a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/DataGrid/BitDataGridDemo.razor.cs b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/DataGrid/BitDataGridDemo.razor.cs index 23091f2b64..753c582df2 100644 --- a/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/DataGrid/BitDataGridDemo.razor.cs +++ b/src/BlazorUI/Demo/Client/Bit.BlazorUI.Demo.Client.Core/Pages/Components/Extras/DataGrid/BitDataGridDemo.razor.cs @@ -212,6 +212,133 @@ UI will be included in the header cell by default. Description = "Optionally specifies sorting rules for this column.", }, ], + }, + new() + { + Id = "BitDataGridPaginator", + Title = "BitDataGridPaginator", + Description = "A component that provides a user interface for pagination.", + Parameters= + [ + new() + { + Name = "GoToFirstButtonTitle", + Type = "string", + DefaultValue = "Go to first page", + Description = "The title of the go to first page button.", + }, + new() + { + Name = "GoToPrevButtonTitle", + Type = "string", + DefaultValue = "Go to previous page", + Description = "The title of the go to previous page button.", + }, + new() + { + Name = "GoToNextButtonTitle", + Type = "string", + DefaultValue = "Go to next page", + Description = "The title of the go to next page button.", + }, + new() + { + Name = "GoToLastButtonTitle", + Type = "string", + DefaultValue = "Go to last page", + Description = "The title of the go to last page button.", + }, + new() + { + Name = "SummaryFormat", + Type = "Func?", + DefaultValue = "null", + Description = "Optionally supplies a format for rendering the page count summary.", + LinkType = LinkType.Link, + Href = "#pagination-state" + }, + new() + { + Name = "SummaryTemplate", + Type = "RenderFragment?", + DefaultValue = "null", + Description = "Optionally supplies a template for rendering the page count summary.", + LinkType = LinkType.Link, + Href = "#pagination-state" + }, + new() + { + Name = "TextFormat", + Type = "Func?", + DefaultValue = "null", + Description = "The optional custom format for the main text of the paginator in the middle of it.", + LinkType = LinkType.Link, + Href = "#pagination-state" + }, + new() + { + Name = "TextTemplate", + Type = "RenderFragment?", + DefaultValue = "null", + Description = "The optional custom template for the main text of the paginator in the middle of it.", + LinkType = LinkType.Link, + Href = "#pagination-state" + }, + new() + { + Name = "Value", + Type = "BitDataGridPaginationState", + DefaultValue = "", + Description = "Specifies the associated pagination state. This parameter is required.", + LinkType = LinkType.Link, + Href = "#pagination-state" + }, + ], + + }, + new() + { + Id = "pagination-state", + Title = "BitDataGridPaginationState", + Description = "A component that provides a user interface for pagination.", + Parameters= + [ + new() + { + Name = "CurrentPageIndex", + Type = "int", + DefaultValue = "0", + Description = "Gets the current zero-based page index.", + }, + new() + { + Name = "ItemsPerPage", + Type = "int", + DefaultValue = "10", + Description = "Gets or sets the number of items on each page.", + }, + new() + { + Name = "LastPageIndex", + Type = "int?", + DefaultValue = "null", + Description = "Gets the zero-based index of the last page, if known. The value will be null until TotalItemCount is known.", + }, + new() + { + Name = "TotalItemCount", + Type = "int?", + DefaultValue = "null", + Description = "Gets the total number of items across all pages, if known. The value will be null until an associated BitDataGrid assigns a value after loading data.", + }, + new() + { + Name = "TotalItemCountChanged", + Type = "EventHandler?", + DefaultValue = "null", + Description = "An event that is raised when the total item count has changed.", + }, + ], }, ]; @@ -345,11 +472,11 @@ protected override async Task OnInitAsync() try { var query = new Dictionary - { - { "search",$"recalling_firm:\"{_virtualSampleNameFilter}\"" }, + { + { "search", $"recalling_firm:\"{_virtualSampleNameFilter}\"" }, { "skip", req.StartIndex }, { "limit", req.Count } - }; + }; var sort = req.GetSortByProperties().SingleOrDefault(); @@ -364,7 +491,7 @@ protected override async Task OnInitAsync() query.Add("sort", $"{sortByColumnName}:{(sort.Direction == BitDataGridSortDirection.Ascending ? "asc" : "desc")}"); } - var url = NavManager.GetUriWithQueryParameters("https://api.fda.gov/food/enforcement.json", query); + var url = NavigationManager.GetUriWithQueryParameters("https://api.fda.gov/food/enforcement.json", query); var data = await HttpClient.GetFromJsonAsync(url, AppJsonContext.Default.FoodRecallQueryResult, req.CancellationToken); @@ -398,7 +525,7 @@ protected override async Task OnInitAsync() query.Add("$orderby", string.Join(", ", req.GetSortByProperties().Select(p => $"{p.PropertyName} {(p.Direction == BitDataGridSortDirection.Ascending ? "asc" : "desc")}"))); } - var url = NavManager.GetUriWithQueryParameters("Products/GetProducts", query); + var url = NavigationManager.GetUriWithQueryParameters("Products/GetProducts", query); var data = await HttpClient.GetFromJsonAsync(url, AppJsonContext.Default.PagedResultProductDto); @@ -698,7 +825,9 @@ .grid .bitdatagrid-paginator nav button {
- + $""Total: {v.TotalItemCount}"")""> + @(state.CurrentPageIndex + 1) / @(state.LastPageIndex + 1) +
"; private readonly string example2CsharpCode = @" private IQueryable allCountries; @@ -743,6 +872,7 @@ public class MedalsModel private readonly string example3RazorCode = @" @using System.Text.Json; @inject HttpClient HttpClient +@inject NavigationManager NavManager