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
45 changes: 44 additions & 1 deletion examples/Demo/Shared/Pages/Lab/IssueTester.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
@page "/issue-tester"
@using System.ComponentModel.DataAnnotations

<FluentUI.Demo.Shared.Pages.DataGrid.Examples.DataGridTypical />
<FluentDataGrid Items="@employees.AsQueryable()" >
<PropertyColumn Property="@(e => e.Id)" />
<PropertyColumn Property="@(e => e.FullName)" />
<PropertyColumn Property="@(e => e.Subdivision)" />
<PropertyColumn Property="@(e => e.Position)" />
</FluentDataGrid>

@code {

public enum Positions
{
employee,
[Display(Name = "HR Manager (DA)")]
HrManager,
[Display(Name = "Project Manager (DA)")]
ProjectManager,
[Display(Name = "Administrator (DA)")]
Administrator
}

public class Employee
{
[Display(Name = "Id")]
public int Id { get; set; }
[Required, Display(Name = "Full Name")]
public string FullName { get; set; }
[Required, Display(Name = "Subdivision")]
public string Subdivision { get; set; }
[Required, Display(Name = "Position")]
public Positions Position { get; set; }

}

private List<Employee> employees = new List<Employee>
{
new Employee { Id = 1, FullName = "John Doe", Subdivision = "IT", Position = Positions.employee },
new Employee { Id = 2, FullName = "Jane Doe", Subdivision = "HR", Position = Positions.HrManager },
new Employee { Id = 3, FullName = "John Smith", Subdivision = "IT", Position = Positions.ProjectManager },
new Employee { Id = 4, FullName = "Jane Smith", Subdivision = "HR", Position = Positions.Administrator }
};


}
15 changes: 14 additions & 1 deletion src/Core/Components/DataGrid/Columns/PropertyColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.FluentUI.AspNetCore.Components.DataGrid.Infrastructure;
using Microsoft.FluentUI.AspNetCore.Components.Extensions;

namespace Microsoft.FluentUI.AspNetCore.Components;

Expand Down Expand Up @@ -73,7 +74,19 @@ protected override void OnParametersSet()
}
else
{
_cellTextFunc = item => compiledPropertyExpression!(item)?.ToString();
_cellTextFunc = item =>
{
var value = compiledPropertyExpression!(item);

if (typeof(TProp).IsEnum)
{
return (value as Enum)?.GetDisplayName();
}
else
{
return value?.ToString();
}
};
}

_sortBuilder = Comparer is not null ? GridSort<TGridItem>.ByAscending(Property, Comparer) : GridSort<TGridItem>.ByAscending(Property);
Expand Down
8 changes: 8 additions & 0 deletions src/Core/Extensions/EnumExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Reflection;

namespace Microsoft.FluentUI.AspNetCore.Components.Extensions;
Expand Down Expand Up @@ -38,4 +39,11 @@ public static class EnumExtensions

return description;
}

public static string GetDisplayName(this Enum enumValue)
{
var memberInfo = enumValue.GetType().GetMember(enumValue.ToString());
var displayAttribute = memberInfo[0].GetCustomAttribute<DisplayAttribute>();
return displayAttribute?.Name ?? enumValue.ToString();
}
}