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

Question: Default sort property #7

Closed
bpkinez opened this issue Feb 16, 2018 · 2 comments
Closed

Question: Default sort property #7

bpkinez opened this issue Feb 16, 2018 · 2 comments

Comments

@bpkinez
Copy link
Contributor

bpkinez commented Feb 16, 2018

Hi Benjamin,

what you think about adding method in AbstractQueryValidator to set certain property as default sort property if we don't want to sort results by primary key 'Id' by default:

public class UserQueryValidator : AbstractQueryValidator<User>
{
    public UserQueryValidator()
    {
        SetDefaultSortProperty("FirstName", x => x.FirstName, descending: true, order: 1);
        SetDefaultSortProperty("LastName", x => x.LastName, descending: false, order: 2);
    }
}

or to go with custom property attribute:

    public class User
    {
        public int Id { get; set; }

        [DefaultSortProperty(descending = true, order = 1)]
        public string FirstName { get; set; }

        [DefaultSortProperty(descending = false, order = 2)]
        public string LastName { get; set; }
        public DateTime DateOfBirth { get; set; }
    }

If we have two or more default order properties it will pick up first by lowest order number and sort result by that property.

@bbartels
Copy link
Owner

Good idea, I am working on a couple of things concerning defaults of ordering/sorting. Trying to get them out later today. I will try to include your suggestion.

@bbartels
Copy link
Owner

Added sorting/filtering/selecting defaults in d6b3d8e.

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

No branches or pull requests

2 participants