Open Closed

Custom display format for extra properties #7343


User avatar
0
mz_s73 created
  • ABP Framework version: v8.0.2
  • UI Type: Blazor Server
  • Database System: EF Core (SQL Server)
  • Steps to reproduce the issue:

I have added an extra property on User entity to store last login datetime. Now on the manage users page how do I configure it to show custom date format like "dd/MM/yyyy HH:mm:ss".

As of now I did find some solution going through the docs & other peoples posts but its not working. Here's what I have done till now:

ObjectExtensionManager.Instance.Modules()
     .ConfigureIdentity(identity =>
     {
         identity.ConfigureUser(user =>
         {
             user.AddOrUpdateProperty<DateTime?>(
                 "LastLoginDateTime",                         
                 property =>
                 {
                     property.DisplayName = LocalizableString.Create<Paddy_Power_Self_ExclusionResource>(CustomIdentityUserPropertyNames.LastLoginDateTimeDisplayName);                             
                     property.UI.OnEditForm.IsVisible = false;
                     property.UI.OnCreateForm.IsVisible = false;
                     property.UI.OnTable.IsVisible = true;

                     property.Api.OnCreate.IsAvailable = false;
                     property.Api.OnUpdate.IsAvailable = false;


                     property.Attributes.Add(new DataTypeAttribute(DataType.DateTime));
                     var format = new DisplayFormatAttribute()
                     {                                 
                         DataFormatString = "dd/MM/yyyy HH:mm:ss",
                         NullDisplayText = ""
                     };
                     property.Attributes.Add(format);
                 }                         
             );
         });
     });

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can try to override the DateTimeExtensionProperty component

    https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.BlazoriseUI/Components/ObjectExtending/DateTimeExtensionProperty.razor#L15

    I will make it support DisplayFormatAttribute in the next version.

    https://github.com/abpframework/abp/issues/20037

  • User Avatar
    0
    mz_s73 created

    Hi Mali, thanks for the response. I have a few questions.

    You mentioned over-riding the date component, would this be for when we edit the information and a modal comes up, because we have disabled editing for the grid.

    All we need is that we can specify a custom date format for the date displayed in cell. We can achieve it by overriding the whole page and specifying the format in data-grid (will take a lot more effort) but just wanted to check with you if there is any other quick alternative

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    All we need is that we can specify a custom date format for the date displayed in cell.

    The DisplayFormatAttribute will work in the next version.

    var format = new DisplayFormatAttribute()
    {                                 
        DataFormatString = "dd/MM/yyyy HH:mm:ss",
        NullDisplayText = ""
    };
    

    You don't need to override the whole page with the custom DateTimeExtensionProperty component.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11