Skip to content

Commit 2abbe9d

Browse files
authored
#871 - Grid enum filter - select text translation support (#905)
* #871 - Grid enum filter - select text translation support added.
1 parent 965b49d commit 2abbe9d

16 files changed

+172
-154
lines changed

Diff for: BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_01_A_Client_Side_Filtering.razor

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<Grid @ref="grid"
2-
TItem="Employee4"
1+
<Grid TItem="Employee4"
32
Class="table table-hover table-bordered table-striped"
43
DataProvider="EmployeesDataProvider"
54
AllowFiltering="true"
@@ -26,14 +25,8 @@
2625
</Grid>
2726

2827
@code {
29-
BlazorBootstrap.Grid<Employee4> grid = default!;
3028
private IEnumerable<Employee4> employees = default!;
3129

32-
protected override async Task OnAfterRenderAsync(bool firstRender)
33-
{
34-
await base.OnAfterRenderAsync(firstRender);
35-
}
36-
3730
private async Task<GridDataProviderResult<Employee4>> EmployeesDataProvider(GridDataProviderRequest<Employee4> request)
3831
{
3932
if (employees is null) // pull employees only one time for client-side filtering, sorting, and paging

Diff for: BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_35_Enum_Filters.razor renamed to BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_05_Enum_Filters.razor

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<Grid @ref="grid"
2-
TItem="User"
1+
<Grid TItem="User"
32
Class="table table-hover table-bordered table-striped"
43
DataProvider="UsersDataProvider"
54
AllowFiltering="true"
@@ -23,14 +22,8 @@
2322
</Grid>
2423

2524
@code {
26-
BlazorBootstrap.Grid<User> grid = default!;
2725
private IEnumerable<User> users = default!;
2826

29-
protected override async Task OnAfterRenderAsync(bool firstRender)
30-
{
31-
await base.OnAfterRenderAsync(firstRender);
32-
}
33-
3427
private async Task<GridDataProviderResult<User>> UsersDataProvider(GridDataProviderRequest<User> request)
3528
{
3629
if (users is null) // pull employees only one time for client-side filtering, sorting, and paging

Diff for: BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_36_Guid_Filters.razor renamed to BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_06_Guid_Filters.razor

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<Grid @ref="grid"
2-
TItem="User"
1+
<Grid TItem="User"
32
Class="table table-hover table-bordered table-striped"
43
DataProvider="UsersDataProvider"
54
AllowFiltering="true"
@@ -26,14 +25,8 @@
2625
</Grid>
2726

2827
@code {
29-
BlazorBootstrap.Grid<User> grid = default!;
3028
private IEnumerable<User> users = default!;
3129

32-
protected override async Task OnAfterRenderAsync(bool firstRender)
33-
{
34-
await base.OnAfterRenderAsync(firstRender);
35-
}
36-
3730
private async Task<GridDataProviderResult<User>> UsersDataProvider(GridDataProviderRequest<User> request)
3831
{
3932
if (users is null) // pull employees only one time for client-side filtering, sorting, and paging

Diff for: BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Filters_Documentation.razor

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
</div>
2828
<Callout Color="CalloutColor.Success">You can set the default filter on more than one GridColumn.</Callout>
2929
<div class="mb-3">The default sorting is enabled on the <b>Id</b> column in the below example.</div>
30-
<Demo Type="typeof(Grid_Demo_05_Set_Default_Filter)" Tabs="true" />
30+
<Demo Type="typeof(Grid_Demo_02_Set_Default_Filter)" Tabs="true" />
3131

3232
<SectionHeading Size="HeadingSize.H2" Text="Disable specific column filter" PageUrl="@pageUrl" HashTagName="disable-specific-column-filter" />
3333
<div class="mb-3">
3434
<code>Filterable</code> parameter is required to disable the filter on a specific column. Add <code>Filterable="false"</code> parameter to GridColumn. The column filter is disabled on the <b>Id</b> column in the below example.
3535
</div>
36-
<Demo Type="typeof(Grid_Demo_06_Disable_Specific_Column_Filter)" Tabs="true" />
36+
<Demo Type="typeof(Grid_Demo_03_Disable_Specific_Column_Filter)" Tabs="true" />
3737

3838
<SectionHeading Size="HeadingSize.H2" Text="Increase filter textbox width" PageUrl="@pageUrl" HashTagName="increase-filter-textbox-width" />
3939
<div class="mb-2">Add <code>FilterTextboxWidth</code> parameter to the GridColumn to increase or decrease the filter textbox width, <code>FilterTextboxWidth</code> parameter is optional.</div>
4040
<Callout>Filter textbox width measured in pixels.</Callout>
41-
<Demo Type="typeof(Grid_Demo_06_Increase_Filter_Textbox_Width)" Tabs="true" />
41+
<Demo Type="typeof(Grid_Demo_04_Increase_Filter_Textbox_Width)" Tabs="true" />
4242

4343
<Callout Color="CalloutColor.Success" Heading="Important">
4444
<p>
@@ -51,10 +51,10 @@
5151
</Callout>
5252

5353
<SectionHeading Size="HeadingSize.H2" Text="Enum filter" PageUrl="@pageUrl" HashTagName="enum-filter" />
54-
<Demo Type="typeof(Grid_Demo_35_Enum_Filters)" Tabs="true" />
54+
<Demo Type="typeof(Grid_Demo_05_Enum_Filters)" Tabs="true" />
5555

5656
<SectionHeading Size="HeadingSize.H2" Text="Guid filter" PageUrl="@pageUrl" HashTagName="guid-filter" />
57-
<Demo Type="typeof(Grid_Demo_36_Guid_Filters)" Tabs="true" />
57+
<Demo Type="typeof(Grid_Demo_06_Guid_Filters)" Tabs="true" />
5858

5959
@code {
6060
private const string pageUrl = "/grid/filters";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<Grid TItem="User"
2+
AllowFiltering="true"
3+
AllowPaging="true"
4+
AllowSorting="true"
5+
Class="table table-hover"
6+
DataProvider="UsersDataProvider"
7+
FiltersRowCssClass="bg-dark text-white bg-opacity-25 border-bottom-0"
8+
FiltersTranslationProvider="GridFiltersTranslationProvider"
9+
HeaderRowCssClass="bg-dark text-white border-bottom-0"
10+
PageSize="10"
11+
PageSizeSelectorVisible="true"
12+
PageSizeSelectorItems="@(new int[] { 5,10,20 })"
13+
PaginationItemsTextFormat="{0} - {1} van {2} artikelen"
14+
ItemsPerPageText="Artikelen per pagina"
15+
EnumFilterSelectText="Selecteer"
16+
Responsive="true">
17+
18+
<GridColumns>
19+
<GridColumn TItem="User" HeaderText="Id" PropertyName="Id">
20+
@context.Id
21+
</GridColumn>
22+
<GridColumn TItem="User" HeaderText="User Name" PropertyName="Name">
23+
@context.Name
24+
</GridColumn>
25+
<GridColumn TItem="User" HeaderText="DOB" PropertyName="DOB">
26+
@context.DOB
27+
</GridColumn>
28+
<GridColumn TItem="User" HeaderText="Status" PropertyName="Status" FilterTextboxWidth="170">
29+
@context.Status
30+
</GridColumn>
31+
</GridColumns>
32+
33+
</Grid>
34+
35+
@code {
36+
private IEnumerable<User> users = default!;
37+
38+
private async Task<IEnumerable<FilterOperatorInfo>> GridFiltersTranslationProvider()
39+
{
40+
var filtersTranslation = new List<FilterOperatorInfo>();
41+
42+
// number/date/boolean
43+
filtersTranslation.Add(new("=", "gelijk aan", FilterOperator.Equals));
44+
filtersTranslation.Add(new("!=", "Niet gelijk", FilterOperator.NotEquals));
45+
// number/date
46+
filtersTranslation.Add(new("<", "Minder dan", FilterOperator.LessThan));
47+
filtersTranslation.Add(new("<=", "Kleiner dan of gelijk aan", FilterOperator.LessThanOrEquals));
48+
filtersTranslation.Add(new(">", "Groter dan", FilterOperator.GreaterThan));
49+
filtersTranslation.Add(new(">=", "Groter dan of gelijk aan", FilterOperator.GreaterThanOrEquals));
50+
// string
51+
filtersTranslation.Add(new("*a*", "Bevat", FilterOperator.Contains));
52+
filtersTranslation.Add(new("a**", "Begint met", FilterOperator.StartsWith));
53+
filtersTranslation.Add(new("**a", "Eindigt met", FilterOperator.EndsWith));
54+
filtersTranslation.Add(new("=", "gelijk aan", FilterOperator.Equals));
55+
// common
56+
filtersTranslation.Add(new("x", "Duidelijk", FilterOperator.Clear));
57+
58+
return await Task.FromResult(filtersTranslation);
59+
}
60+
61+
62+
private async Task<GridDataProviderResult<User>> UsersDataProvider(GridDataProviderRequest<User> request)
63+
{
64+
if (users is null) // pull employees only one time for client-side filtering, sorting, and paging
65+
users = GetUsers(); // call a service or an API to pull the employees
66+
67+
return await Task.FromResult(request.ApplyTo(users));
68+
}
69+
70+
private IEnumerable<User> GetUsers()
71+
{
72+
return new List<User>
73+
{
74+
new User { Id = 107, Name = "Alice", DOB = new DateOnly(1998, 11, 17), Status = UserStatus.Registered },
75+
new User { Id = null, Name = "Bob", DOB = new DateOnly(1985, 1, 5), Status = UserStatus.Verified },
76+
new User { Id = 106, Name = "John", DOB = new DateOnly(1995, 4, 17), Status = UserStatus.Registered },
77+
new User { Id = 104, Name = "Pop", DOB = new DateOnly(1985, 6, 8), Status = UserStatus.Registered },
78+
new User { Id = 105, Name = "Ronald", DOB = new DateOnly(1991, 8, 23), Status = UserStatus.VerificationPending },
79+
new User { Id = 102, Name = "Line", DOB = new DateOnly(1977, 1, 12), Status = UserStatus.VerificationPending },
80+
new User { Id = 101, Name = "Daniel", DOB = new DateOnly(1977, 1, 12), Status = UserStatus.Registered },
81+
new User { Id = 108, Name = "Zayne", DOB = new DateOnly(1991, 1, 1), Status = UserStatus.Verified },
82+
new User { Id = 109, Name = "Isha", DOB = null, Status = UserStatus.Verified },
83+
new User { Id = 110, Name = "Vijay", DOB = new DateOnly(1990, 7, 1), Status = UserStatus.Verified },
84+
};
85+
}
86+
87+
public record class User
88+
{
89+
public int? Id { get; set; }
90+
public string? Name { get; set; }
91+
public DateOnly? DOB { get; set; }
92+
public UserStatus Status { get; set; }
93+
}
94+
95+
public enum UserStatus
96+
{
97+
Registered,
98+
VerificationPending,
99+
Verified
100+
}
101+
}

Diff for: BlazorBootstrap.Demo.RCL/Components/Pages/Grid/11-translations/Grid_Demo_31_Translations.razor

-89
This file was deleted.

Diff for: BlazorBootstrap.Demo.RCL/Components/Pages/Grid/11-translations/Grid_Translations_Documentation.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<SectionHeading Size="HeadingSize.H2" Text="Translations" PageUrl="@pageUrl" HashTagName="translations" />
1313
<div class="mb-3">In the example below, you will see translations related to pagination and filters in <b>Dutch</b>.</div>
14-
<Demo Type="typeof(Grid_Demo_31_Translations)" Tabs="true" />
14+
<Demo Type="typeof(Grid_Demo_01_Translations)" Tabs="true" />
1515

1616
@code {
1717
private const string pageUrl = "/grid/translations";

Diff for: blazorbootstrap/Components/Grid/Grid.razor

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@inherits BlazorBootstrapComponentBase
33
@typeparam TItem
44

5-
<CascadingValue Value="@(this)" IsFixed="true">
5+
<CascadingValue Value="@(this)" Name="Parent" IsFixed="true">
66
@ChildContent
77
</CascadingValue>
88

@@ -58,7 +58,8 @@
5858
<th class="@string.Join(" ", columnClassList)" style="@string.Join(";", columnStyleList)">
5959
@if (column.Filterable)
6060
{
61-
<GridColumnFilter FilterButtonColor="@column.FilterButtonColor"
61+
<GridColumnFilter EnumFilterSelectText="@EnumFilterSelectText"
62+
FilterButtonColor="@column.FilterButtonColor"
6263
FilterButtonCSSClass="@column.FilterButtonCSSClass"
6364
FilterOperator="@column.FilterOperator"
6465
FilterValue="@column.FilterValue"

Diff for: blazorbootstrap/Components/Grid/Grid.razor.cs

+9
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,15 @@ private void SetFilters(IEnumerable<FilterItem> filterItems)
662662
[Parameter]
663663
public string EmptyText { get; set; } = "No records to display";
664664

665+
/// <summary>
666+
/// Gets or sets the enum filter select text.
667+
/// </summary>
668+
/// <remarks>
669+
/// Default value is 'Select'.
670+
/// </remarks>
671+
[Parameter]
672+
public string? EnumFilterSelectText { get; set; } = "Select";
673+
665674
/// <summary>
666675
/// Gets or sets the filters row css class.
667676
/// </summary>

Diff for: blazorbootstrap/Components/Grid/GridColumn.razor.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,8 @@ private async Task OnSortClickAsync()
411411
[Parameter]
412412
public bool IsDefaultSortColumn { get; set; } = false;
413413

414-
[CascadingParameter] public Grid<TItem> Parent { get; set; } = default!;
414+
[CascadingParameter(Name = "Parent")]
415+
public Grid<TItem> Parent { get; set; } = default!;
415416

416417
/// <summary>
417418
/// Gets or sets the property name.

Diff for: blazorbootstrap/Components/Grid/GridColumnFilter.razor

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<DropdownToggleButton Class="px-1" Style="@filterStyle">
5959
@if (string.IsNullOrWhiteSpace(filterValue))
6060
{
61-
<span class="px-2">Select</span>
61+
<span class="px-2">@EnumFilterSelectText</span>
6262
}
6363
else
6464
{

Diff for: blazorbootstrap/Components/Grid/GridColumnFilter.razor.cs

+3
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ or StringConstants.PropertyTypeNameDecimal
147147

148148
#region Properties, Indexers
149149

150+
[Parameter]
151+
public string? EnumFilterSelectText { get; set; }
152+
150153
/// <summary>
151154
/// Gets or sets the filter button color.
152155
/// </summary>

0 commit comments

Comments
 (0)