From 93bab5779bb0077b0e182ad339ea42d4bb29a165 Mon Sep 17 00:00:00 2001 From: Raj Kumar Sri Ramulu Date: Tue, 11 Mar 2025 22:38:08 -0600 Subject: [PATCH 1/4] Updating the Enum filter values to Display attribute for name --- .../Components/Grid/GridColumnFilter.razor | 5 +++-- blazorbootstrap/Extensions/TypeExtensions.cs | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/blazorbootstrap/Components/Grid/GridColumnFilter.razor b/blazorbootstrap/Components/Grid/GridColumnFilter.razor index 4321a1811..72e883b1b 100644 --- a/blazorbootstrap/Components/Grid/GridColumnFilter.razor +++ b/blazorbootstrap/Components/Grid/GridColumnFilter.razor @@ -62,7 +62,7 @@ } else { - @filterValue + @(PropertyType!.GetDisplayName(filterValue)) } @@ -70,7 +70,8 @@ { @foreach (var item in Enum.GetValues(PropertyType!)) { - @item + var name = PropertyType!.GetDisplayName(Enum.GetName(PropertyType!, item)); + @name } } diff --git a/blazorbootstrap/Extensions/TypeExtensions.cs b/blazorbootstrap/Extensions/TypeExtensions.cs index bddf250d1..28391d57b 100644 --- a/blazorbootstrap/Extensions/TypeExtensions.cs +++ b/blazorbootstrap/Extensions/TypeExtensions.cs @@ -1,4 +1,7 @@ namespace BlazorBootstrap; +using System.ComponentModel.DataAnnotations; +using System.Reflection; + /// /// Various extension methods for . @@ -82,5 +85,16 @@ public static string GetPropertyTypeName(this Type type, string propertyName) return type.GetProperty(propertyName)?.PropertyType; } + public static string? GetDisplayName(this Type type, string? name) + { + if (name != null) + { + var attr = type!.GetMember(name).FirstOrDefault()?.GetCustomAttribute(); + name = attr?.Name ?? name; + } + + return name; + } + #endregion } From 540278e5d0ce2fb179979d103029aa96eb2c0776 Mon Sep 17 00:00:00 2001 From: Raj Kumar Sri Ramulu Date: Tue, 11 Mar 2025 22:38:27 -0600 Subject: [PATCH 2/4] Updated the example to use the Display attribute --- .../Pages/Grid/03-filters/Grid_Demo_05_Enum_Filters.razor | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_05_Enum_Filters.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_05_Enum_Filters.razor index f642a5b1d..4c27dac36 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_05_Enum_Filters.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_05_Enum_Filters.razor @@ -1,4 +1,6 @@ - - @context.Status + @(typeof(UserStatus).GetDisplayName(context.Status)) @@ -60,6 +62,7 @@ public enum UserStatus { Registered, + [Display(Name = "Pending Verification")] VerificationPending, Verified } From 54bd37a43d7b07df785ab11bceca9a44d6306035 Mon Sep 17 00:00:00 2001 From: Raj Kumar Sri Ramulu Date: Tue, 25 Mar 2025 20:17:31 -0600 Subject: [PATCH 3/4] Fixed the param related error --- .../Pages/Grid/03-filters/Grid_Demo_05_Enum_Filters.razor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_05_Enum_Filters.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_05_Enum_Filters.razor index 4c27dac36..1dba97a95 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_05_Enum_Filters.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_05_Enum_Filters.razor @@ -17,7 +17,7 @@ @context.DOB - @(typeof(UserStatus).GetDisplayName(context.Status)) + @(typeof(UserStatus).GetDisplayName(context.Status.ToString())) From 53dd13d7737b3b797561a621726d0b3ec9846780 Mon Sep 17 00:00:00 2001 From: Vikram Reddy Date: Wed, 26 Mar 2025 22:12:02 +0530 Subject: [PATCH 4/4] Example updates --- .../Pages/Grid/03-filters/Grid_Demo_06_Guid_Filters.razor | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_06_Guid_Filters.razor b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_06_Guid_Filters.razor index 9d226d025..16c622a18 100644 --- a/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_06_Guid_Filters.razor +++ b/BlazorBootstrap.Demo.RCL/Components/Pages/Grid/03-filters/Grid_Demo_06_Guid_Filters.razor @@ -1,4 +1,6 @@ - - @context.Status + @(typeof(UserStatus).GetDisplayName(context.Status.ToString())) @@ -64,6 +66,7 @@ public enum UserStatus { Registered, + [Display(Name = "Pending Verification")] VerificationPending, Verified }