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..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 @@ -1,4 +1,6 @@ - - @context.Status + @(typeof(UserStatus).GetDisplayName(context.Status.ToString())) @@ -60,6 +62,7 @@ public enum UserStatus { Registered, + [Display(Name = "Pending Verification")] VerificationPending, Verified } 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 } 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 }