Open Closed

How to add a new TableColumn using "ExtraProperties" #7239


User avatar
0
skander created
  • ABP Framework version: v8.0.3
  • UI Type: Blazor WASM

Hello, I'm overriding the page UserManagement and I would like to add new columns to the table such as Address, City etc. to the IdentityUser

I thought I can use the property ExtraProperties to add my custom properties but then I'm not sure how can I access my custom keys in TableColumn Data property?

This is what I have so far but it didn't work for me:

Error:

System.ArgumentException: Cannot detect the member of Volo.Abp.Data.ExtraPropertyDictionary (Parameter 'Address')
   at Blazorise.DataGrid.Utils.FunctionCompiler.GetSafePropertyOrField(Expression item, String propertyOrFieldName)
   at Blazorise.DataGrid.Utils.FunctionCompiler.GetSafePropertyOrField(Expression item, String propertyOrFieldName)
   at Blazorise.DataGrid.Utils.FunctionCompiler.CreateValueGetter[IdentityUserDto](String fieldName)
   at Blazorise.DataGrid.DataGridColumn`1[[Volo.Abp.Identity.IdentityUserDto, Volo.Abp.Identity.Pro.Application.Contracts, Version=8.0.3.0, Culture=neutral, PublicKeyToken=null]].<.ctor>b__10_2()

Adding columns:

Adding extra properties by overriding the function GetEntitiesAsync


Is there something I'm doing wrong? I'm open for suggestions or other ways to achieve that

Note that my address, city etc. live in another table right now called UserProfile.

Thanks


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

    hi

    The AbpExtensibleDataGrid support the ExtraProperties, see https://docs.abp.io/en/abp/latest/Object-Extensions

    Can you share all your custom code?

  • User Avatar
    0
    skander created

    Hi maliming

    I saw that doc already, but I don't see any mention about AbpExtensibleDataGrid. I went to read some source code of yours and I found that a way to achieve that was to use Data and PropertyName at the same time.

    But right now, I have another issue with the sorting, whenever I want to sort this ExtraProperty, it says:

    No property or field 'Addresss' exists in type 'IdentityUser'

    So I assume the AbpExtensibleDataGrid uses backend to sort and since Address is indeed not a column in my entity, it fails.

    Do you have any clue how can I still sort but frontend only and avoid to sort backend for any "ExtraProperty" ?

    My custom code has change since because I tried other ways but here's basically what it looks like:

    Blazor

    Blazor.cs

    [ExposeServices(typeof(UserManagement))]
    [Dependency(ReplaceServices = true)]
    public partial class MyUserManagement
    {
        [Inject]
        public required IUserProfileAppService UserProfileAppService { get; set; }
    	
        protected override ValueTask SetTableColumnsAsync()
        {
            UserManagementTableColumns.AddRange(
            [
                new TableColumn
                {
                    Title = L["Email"],
                    Data = "Email",
                    Sortable = true
                },
    	    // Here I consume and try to sort the extra property
                new TableColumn
                {
                    Title = "Address",
                    Data = "ExtraProperties[Address]",
                    PropertyName = "Addresss",
                    Sortable = true // <== this won't work!
                },
            ]);
    
            UserManagementTableColumns.AddRange(GetExtensionTableColumns("Identity", "User"));
    
            return ValueTask.CompletedTask;
    	}
    	
        protected override async Task GetEntitiesAsync()
        {
            await base.GetEntitiesAsync();
    
            await ExtendedEntities();
        }
    	
    		
        private async Task ExtendedEntities()
        {
            // I act directly on the IdentityUserDto, because the extra properties come from another db table
            var userIds = Entities.Select(x => x.Id).ToList();
            var userProfiles = await UserProfileAppService.GetListUserProfilesAsync(userIds);
            var userProfilesDict = userProfiles.ToDictionary(x => x.InternalUserId, x => x);
    
            foreach (var identityUserDto in Entities)
            {
                var profile = userProfilesDict.GetOrDefault(identityUserDto.Id);
    
                if (profile is null)
                {
                    continue;
                }
    
    	    // Here I add the extra property
                identityUserDto.ExtraProperties["Address"] = profile.Address;
            }
        }
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    https://support.abp.io/QA/Questions/784/Filter-User-list-by-new-extra-property https://support.abp.io/QA/Questions/6721/Find-user-by-extend-property

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I saw you closed the question. Have you solved it?

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19