diff --git a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/TableColumns/TableColumn.cs b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/TableColumns/TableColumn.cs index cde7cd34aa..ce87c4b5a7 100644 --- a/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/TableColumns/TableColumn.cs +++ b/framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/Extensibility/TableColumns/TableColumn.cs @@ -14,6 +14,7 @@ namespace Volo.Abp.AspNetCore.Components.Extensibility.TableColumns [CanBeNull] public Type Component { get; set; } public List Actions { get; set; } + public Func ValueConverter { get; set; } public TableColumn() { diff --git a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs index c4f953139c..8675368e82 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/AbpCrudPageBase.cs @@ -18,6 +18,7 @@ using Volo.Abp.AspNetCore.Components.Extensibility.TableColumns; using Volo.Abp.Localization; using Volo.Abp.Authorization; using Volo.Abp.BlazoriseUI.Components; +using Volo.Abp.BlazoriseUI.Components.ObjectExtending; using Volo.Abp.ObjectExtending.Modularity; using Volo.Abp.ObjectExtending; @@ -503,18 +504,24 @@ namespace Volo.Abp.BlazoriseUI } else { - string displayFormat = null; + var column = new TableColumn + { + Title = propertyInfo.GetLocalizedDisplayName(StringLocalizerFactory), + Data = $"ExtraProperties[{propertyInfo.Name}]" + }; + if (propertyInfo.IsDate() || propertyInfo.IsDateTime()) { - displayFormat = propertyInfo.GetDateEditInputFormatOrNull(); + column.DisplayFormat = propertyInfo.GetDateEditInputFormatOrNull(); } - yield return new TableColumn + if (propertyInfo.Type.IsEnum) { - Title = propertyInfo.GetLocalizedDisplayName(StringLocalizerFactory), - Data = $"ExtraProperties[{propertyInfo.Name}]", - DisplayFormat = displayFormat - }; + column.ValueConverter = (val) => + EnumHelper.GetLocalizedMemberName(propertyInfo.Type, val, StringLocalizerFactory); + } + + yield return column; } } } diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor index baea37bea1..718974c81e 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor @@ -1,6 +1,7 @@ @typeparam TItem @using Blazorise.DataGrid; @using Volo.Abp.Data +@using Volo.Abp.BlazoriseUI.Components.ObjectExtending + } else { @@ -68,31 +69,45 @@ var propertyValue = entity.GetProperty(propertyName); if (propertyValue != null && propertyValue.GetType() == typeof(bool)) { - if ((bool)propertyValue) + if ((bool) propertyValue) { - + } else { - + } } else { - if (column.DisplayFormat == null) + if (column.ValueConverter != null) { - @(propertyValue) + if (column.DisplayFormat == null) + { + @(column.ValueConverter(propertyValue)) + } + else + { + @(string.Format(column.DisplayFormat, column.ValueConverter(propertyValue))) + } } else { - @(string.Format(column.DisplayFormat, propertyValue)) + if (column.DisplayFormat == null) + { + @(propertyValue) + } + else + { + @(string.Format(column.DisplayFormat, propertyValue)) + } } + } } } - } } } diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor.cs index f1e94a7c7e..9d9cf791a3 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/AbpExtensibleDataGrid.razor.cs @@ -7,6 +7,7 @@ using JetBrains.Annotations; using Volo.Abp.AspNetCore.Components.Extensibility.TableColumns; using System.Linq; using System.Text.RegularExpressions; +using Microsoft.Extensions.Localization; namespace Volo.Abp.BlazoriseUI.Components { @@ -31,6 +32,9 @@ namespace Volo.Abp.BlazoriseUI.Components [Parameter] public IEnumerable Columns { get; set; } + [Inject] + public IStringLocalizerFactory StringLocalizerFactory { get; set; } + protected virtual RenderFragment RenderCustomTableColumnComponent(Type type, object data) { return (builder) => diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/EnumHelper.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/EnumHelper.cs new file mode 100644 index 0000000000..4b4e2fafd5 --- /dev/null +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/EnumHelper.cs @@ -0,0 +1,33 @@ +using Microsoft.Extensions.Localization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.Localization; + +namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending +{ + public static class EnumHelper + { + public static string GetLocalizedMemberName(Type enumType, object value, IStringLocalizerFactory stringLocalizerFactory) + { + var memberName = enumType.GetEnumName(value); + var localizedMemberName = AbpInternalLocalizationHelper.LocalizeWithFallback( + new[] + { + stringLocalizerFactory.CreateDefaultOrNull() + }, + new[] + { + $"Enum:{enumType.Name}.{memberName}", + $"{enumType.Name}.{memberName}", + memberName + }, + memberName + ); + + return localizedMemberName; + } + } +} diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor index 875599725b..982a56b621 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor @@ -4,7 +4,7 @@ @PropertyInfo.GetLocalizedDisplayName(StringLocalizerFactory) - @foreach (var item in GetSelectItemsFromEnum()) { @item.Text diff --git a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor.cs b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor.cs index 6afc4f5254..952a55728b 100644 --- a/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor.cs +++ b/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/SelectExtensionProperty.razor.cs @@ -11,27 +11,18 @@ namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending public partial class SelectExtensionProperty : ComponentBase where TEntity : IHasExtraProperties { - [Inject] - public IStringLocalizerFactory StringLocalizerFactory { get; set; } + [Inject] public IStringLocalizerFactory StringLocalizerFactory { get; set; } - [Parameter] - public TEntity Entity { get; set; } + [Parameter] public TEntity Entity { get; set; } - [Parameter] - public ObjectExtensionPropertyInfo PropertyInfo { get; set; } + [Parameter] public ObjectExtensionPropertyInfo PropertyInfo { get; set; } public int SelectedValue { - get - { - return Entity.GetProperty(PropertyInfo.Name); - } - set - { - Entity.SetProperty(PropertyInfo.Name, value); - } + get { return Entity.GetProperty(PropertyInfo.Name); } + set { Entity.SetProperty(PropertyInfo.Name, value); } } - + protected virtual IEnumerable> GetSelectItemsFromEnum() { var isNullableType = Nullable.GetUnderlyingType(PropertyInfo.Type) != null; @@ -45,37 +36,21 @@ namespace Volo.Abp.BlazoriseUI.Components.ObjectExtending foreach (var enumValue in enumType.GetEnumValues()) { - var memberName = enumType.GetEnumName(enumValue); - var localizedMemberName = AbpInternalLocalizationHelper.LocalizeWithFallback( - new[] - { - // containerLocalizer, - StringLocalizerFactory.CreateDefaultOrNull() - }, - new[] - { - $"Enum:{enumType.Name}.{memberName}", - $"{enumType.Name}.{memberName}", - memberName - }, - memberName - ); - yield return new SelectItem { - Value = (int)enumValue, - Text = localizedMemberName + Value = (int) enumValue, + Text = EnumHelper.GetLocalizedMemberName(enumType, enumValue, StringLocalizerFactory) }; } } - - protected virtual void SelectedValueChanged(int value) + protected override void OnInitialized() { - SelectedValue = value; + SelectedValue = 0; } } + public class SelectItem { public string Text { get; set; }