DataGrid: Allow using enum with Display attributes for filter #7621#8581
DataGrid: Allow using enum with Display attributes for filter #7621#8581ScarletKuro merged 33 commits intoMudBlazor:devfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #8581 +/- ##
==========================================
+ Coverage 89.82% 90.98% +1.15%
==========================================
Files 412 410 -2
Lines 11878 12546 +668
Branches 2364 2451 +87
==========================================
+ Hits 10670 11415 +745
+ Misses 681 578 -103
- Partials 527 553 +26 ☔ View full report in Codecov by Sentry. |
|
It should probably fallback so you don't need both attributes on the enum, like for example: /// <summary>
/// Returns the best display name for the given type.
/// </summary>
/// <param name="shortName">Try to find the shorter version of the name</param>
public static string GetDisplayName(this Type type, bool shortName = false) =>
(shortName ? type?.GetCustomAttribute<DisplayAttribute>()?.ShortName : null) ??
type?.GetCustomAttribute<DisplayAttribute>()?.Name ??
type?.GetCustomAttribute<DisplayNameAttribute>()?.DisplayName ??
type?.GetCustomAttribute<DescriptionAttribute>()?.Description ??
type?.Name;But Isn't there a source generator for this or something? @ScarletKuro |
The source generator is only working with the I do not understand why I'm also not sure if this is fixing localization issues, what if you want multi-languages for the enum? I will let @tjscience and maybe @mikes-gh (if he is interested) to review this instead. |
|
Hi. I appreciate you keep this branch up to date. But as you can see your code is failing to build:
|
|
@meenzen, wouldn't it be better to do something like injecting the -<MudSelectItem T="Enum" Value="@((Enum)item)">@item</MudSelectItem>
+<MudSelectItem T="Enum" Value="@Localizer[item]</MudSelectItem>It would be more universal. There is one problem that enumeration names can clash like this: public enum Enum1
{
Test1
}
public enum Enum2
{
Test1
}But maybe we could use a bit of reflection and do something like Is there a possibility to add support for |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
@henon @meenzen I reworked it completely, again. The main improvement is that it’s now part of The first one is a hard-coded string, second if it finds the key in the |
|
Should we add some simple docs? |
we can do it after |
…or#7621 (MudBlazor#8581) Co-authored-by: Artyom M <[email protected]>
Description
Fix: #7621
Fix: #5766
Using name of enum in filter of DataGrid by Display attribute, for example:
if attribute non exists, will be returns default value of enum
Added
How Has This Been Tested?
Compiled and test in my project
Types of changes
Checklist:
dev).