Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<Grid TItem="User"
@using System.ComponentModel.DataAnnotations

<Grid TItem="User"
Class="table table-hover table-bordered table-striped"
DataProvider="UsersDataProvider"
AllowFiltering="true"
Expand All @@ -15,7 +17,7 @@
@context.DOB
</GridColumn>
<GridColumn TItem="User" HeaderText="Status" PropertyName="Status" FilterTextboxWidth="170">
@context.Status
@(typeof(UserStatus).GetDisplayName(context.Status.ToString()))
</GridColumn>
</GridColumns>

Expand Down Expand Up @@ -60,6 +62,7 @@
public enum UserStatus
{
Registered,
[Display(Name = "Pending Verification")]
VerificationPending,
Verified
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<Grid TItem="User"
@using System.ComponentModel.DataAnnotations

<Grid TItem="User"
Class="table table-hover table-bordered table-striped"
DataProvider="UsersDataProvider"
AllowFiltering="true"
Expand All @@ -18,7 +20,7 @@
@context.DOB
</GridColumn>
<GridColumn TItem="User" HeaderText="Status" PropertyName="Status" FilterTextboxWidth="170">
@context.Status
@(typeof(UserStatus).GetDisplayName(context.Status.ToString()))
</GridColumn>
</GridColumns>

Expand Down Expand Up @@ -64,6 +66,7 @@
public enum UserStatus
{
Registered,
[Display(Name = "Pending Verification")]
VerificationPending,
Verified
}
Expand Down
5 changes: 3 additions & 2 deletions blazorbootstrap/Components/Grid/GridColumnFilter.razor
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@
}
else
{
<span class="px-2">@filterValue</span>
<span class="px-2">@(PropertyType!.GetDisplayName(filterValue))</span>
}
</DropdownToggleButton>
<DropdownMenu Class="bb-dropdown-menu-enum" Style="max-height: var(--bb-grid-filter-dropdown-max-height); overflow-x: hidden; overflow-y: auto;">
@if (PropertyType is not null)
{
@foreach (var item in Enum.GetValues(PropertyType!))
{
<DropdownItem @onclick="@(async () => await OnEnumFilterValueChangedAsync(item))">@item</DropdownItem>
var name = PropertyType!.GetDisplayName(Enum.GetName(PropertyType!, item));
<DropdownItem @onclick="@(async () => await OnEnumFilterValueChangedAsync(item))">@name</DropdownItem>
}
}
</DropdownMenu>
Expand Down
14 changes: 14 additions & 0 deletions blazorbootstrap/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace BlazorBootstrap;
using System.ComponentModel.DataAnnotations;
using System.Reflection;


/// <summary>
/// Various extension methods for <see cref="Type" />.
Expand Down Expand Up @@ -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<DisplayAttribute>();
name = attr?.Name ?? name;
}

return name;
}

#endregion
}
Loading