orchardcmsorchardcms-1.9

How to sort content based on values in custom part?


I created a PersonPart and attached it to my Employee type. It contains a first name and a last name and implements ITitleAspect so that when I create a bunch of Employees, they don't all show up as "Employee" in the content list. Now I want to create a Projection that displays all employees ordered by their last name alphabetically.

How can I accomplish this? Is there any interface I can implement to make FirstName and LastName available as sort criteria?

public class PersonPart : ContentPart<PersonPartRecord>, ITitleAspect
{
    [Required]
    [DisplayName("First name")]
    public string FirstName
    {
        get { return Retrieve(r => r.FirstName); }
        set { Store(r => r.FirstName, value); }
    }

    [Required]
    [DisplayName("Last name")]
    public string LastName
    {
        get { return Retrieve(r => r.LastName); }
        set { Store(r => r.LastName, value); }
    }

    public string Title
    {
        get { return LastName + " " + FirstName; }
    }
}

Solution

  • To add new bindings in Orchard to use in custom queries, you have to add these bindings as following:

    1. You should go to Bindings page as following:

    Bindings

    then press on Add a New Binding button.

    1. In Add a Binding page, you will see all your records properties (it will not include your ContentPart properties if it's does not has a ContentPartRecord), which you can add new binding for them:

    Add a Binding

    Here, you can select the property you want to add binding for.

    1. Then, You are free to enter the Display text and Description for your property binding:

    Binding

    1. Now, if you go to your query edit page, and try to add a new filter for it, you will see the new binding there (notice that the display name you entered in the previous step is very important here to describe your binding to be very clear for others):

    Add a Filter

    1. Finally, you will see the newly created binding in your Edit Query page:

    Edit Query