-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed
Labels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-quickgrid
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
Currently, QuickGrid's PropertyColumn
gets the name of the property and use it as a title in the header of the table, as shown here.
It would be nice to get the text of the header based on the property's metadata.
Describe the solution you'd like
I suggest to get the text of the title following these rules, in this order of priority or another you judge better:
- [DisplayName] of property.
- [Display] of property.
- [DisplayName] of base property.
- [Display] of base property.
- Name of the property.
So, the code would be something like:
var propertyExpression = (MemberExpression)Property.Body;
var propertyName = propertyExpression.Member.Name;
var propertyType = propertyExpression.Expression.Type;
var propertyInfo = propertyType.GetProperty(propertyName);
Title =
propertyInfo.GetCustomAttributes<DisplayNameAttribute>(false).FirstOrDefault()?.DisplayName ??
propertyInfo.GetCustomAttributes<DisplayAttribute>(false).FirstOrDefault()?.Name ??
propertyInfo.GetCustomAttributes<DisplayNameAttribute>(true).FirstOrDefault()?.DisplayName ??
propertyInfo.GetCustomAttributes<DisplayAttribute>(true).FirstOrDefault()?.Name ??
propertyName;
In my tests, this works fine with localization if you declare a property like this:
[Display(Name = nameof(AppResources.Name), ResourceType = typeof(AppResources))]
public string CustomerName { get; set; }
Additional context
No response
boukenka
Metadata
Metadata
Assignees
Labels
area-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-quickgrid