Skip to content

Is it possible to Sort on multiple fields? #63

Answered by enisn
AdamAdu3 asked this question in Q&A
Discussion options

You must be logged in to vote

It's a good point. Filtering multiple fields in a single field is not Open API Specs friendly and it's not supported by AutoFilterer by default. But I can share an example code that helps you to achieve this goal.

  1. Create your own FilterBase class
public class MultipleSortingFilterBase : PaginationFilterBase
{
    public override IOrderedQueryable<TSource> ApplyOrder<TSource>(IQueryable<TSource> source)
    {
        // books?sort=title asc,totalPage desc

        var sortings = this.Sort.Split(',');

        var query = source;

        for (int i = 0; i < sortings.Length; i++)
        {
            if (i == 0)
            {
                query = ApplyOrderBy(query, sortings[i].Split(' '

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@enisn
Comment options

Answer selected by AdamAdu3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants