The Wayback Machine - https://web.archive.org/web/20220207132628/https://github.com/dotnet/aspnetcore/issues/40031
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASP.NET CORE - Virtualization - API Modification proposal - ItemsProviderRequest #40031

Open
boukenka opened this issue Feb 7, 2022 · 0 comments
Open

Comments

@boukenka
Copy link

@boukenka boukenka commented Feb 7, 2022

Background and Motivation

Following the ASP.NET CORE 6 - Blazor - Infer the component type for child components from a method issue, I am currently using the option C. This means using the delegate below:

public delegate ValueTask<ItemsProviderResult<TItem>> ItemsProviderDelegate<TItem>(ItemsProviderRequest request);

This method has the parameter: ItemsProviderRequest. However, this parameter does not contain any sorting information.

Proposed API

The goal would be to add sorting information to the ItemsProviderRequest parameter.

namespace Microsoft.AspNetCore.Components.Web.Virtualization;
{
    public readonly struct ItemsProviderRequest
    {
+       public List<SortRequirement> SortRequirements { get; }
...
         public ItemsProviderRequest(int startIndex, int count, CancellationToken cancellationToken, 
+               List<SortRequirement> sortRequirements = default!)
        {
            StartIndex = startIndex;
            Count = count;
+           SortRequirements = sortRequirements;
            CancellationToken = cancellationToken;
         }
    }
}
public readonly struct SortRequirement
{
    public int Order { get; }
    public string FieldName { get; }
    public SortDirection Direction { get; }

    public SortRequirement(int order, string fieldName, SortDirection direction)
    {
        Order = order;
        FieldName = fieldName;
        Direction = direction;
    }
}

public enum SortDirection
{
    ASC,
    DESC
}

Usage Examples

When calling a remote provider, the sort requirement can be added. This will give for example the possibility to apply the sorting directly when querying the database. This will be very useful when using a pager. The number of rows that are returned is limited and a previous sort will already be applied. The typical use is a table/grid where there is a multiple sort option.

image

Risks

None. Because the SortRequirements parameter is optional. There will be no breaking change for the current API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant