Open Closed

Sort order of LookupDto to DisplayName #1482


User avatar
0
cellero created

Project: Blazor Server, EntityFramework, V4.3.0

Please advise how to set the sort order of the items to DisplayName instead of the Guid.
This should be the default behaviour.

private IReadOnlyList<LookupDto<Guid?>> Users { get; set; } = new List<LookupDto<Guid?>>();
UsersNullable = (await XXXXAppService.GetAppUserLookupAsync(new LookupRequestDto { Filter = newValue })).Items;

Thank you.


4 Answer(s)
  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    If your LookupRequestDto inherits from PagedAndSortedResultRequestDto you can use Sortingproperty to apply an order.

    private IReadOnlyList<LookupDto<Guid?>> Users { get; set; } = new List<LookupDto<Guid?>>();
    UsersNullable = (await XXXXAppService.GetAppUserLookupAsync(new LookupRequestDto 
    { 
        Filter = newValue,
        Sorting = "UserName"
    })).Items;
    
    

    And if you implement on your own the repository:

    
    public async Task<PagedResultDto<LookupDto<Guid?>>> GetAppUserLookupAsync(PagedAndSortedResultRequestDto input)
    {
        var list = await UserRepository.GetPagedListAsync(input.SkipCount, input.MaxResultCount, input.Sorting);
    
        return new PagedResultDto<LookupDto<Guid?>>(
            await UserRepository.GetCountAsync(),
            ObjectMapper.Map<List<AppUser>, List<LookupDto<Guid?>>(list)
        );
    }
    
    
  • User Avatar
    0
    cellero created

    The code I inlucded in the question was auto generated by ABP suite. It is the code generated when a navigation property is included in the entity. You can see by the code naming convention that this is the case.

    I don't want to implement another repsoitory or alter the automatically generated ABP suite code, can this be raised as an issue as it makes no sense to have no sort on LookupDto results. LookupDto only have two fields, Key (Guid) and DisplayName - the value is what the end user sees and therefore LookupDto should by default be sorted by the DisplayName.

    Thank you

  • User Avatar
    0
    alper created
    Support Team Director

    Add a sorting property

    Use it in the query

  • User Avatar
    0
    cellero created

    Thank you.
    The query option is what will work for me.

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