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

Sort by Multiple Columns #101

Open
Nicholas-Westby opened this issue Mar 2, 2019 · 3 comments
Open

Sort by Multiple Columns #101

Nicholas-Westby opened this issue Mar 2, 2019 · 3 comments

Comments

@Nicholas-Westby
Copy link
Contributor

Right now, it seems that you can only set one default sort and you can only click one column header at at time in list view to change the sort.

What I'd like to do is set a default sort using multiple columns.

My specific scenario is that I'd like to use Fluidity to show the latest reviews (sort by date descending) that are marked as not yet approved (sort by approved, starting with unapproved first).

This would allow the editor to see the most recent reviews that have not yet been approved.

As far as I can tell, this does not seem possible right now. My temporary (less than ideal) solution is to sort by date only:

collection.SetSortProperty(x => x.Created, SortDirection.Descending);

I tried this, but it seemed to just be sorting by date:

collection
    .SetSortProperty(x => x.Active, SortDirection.Descending)
    .SetSortProperty(x => x.Created, SortDirection.Descending);
@mattbrailsford
Copy link
Owner

Will need to have a look at adding ability to set a default sort order with multiple fields, but it's unlikely we'll update the UI to allow sorting on multiple (mostly because a) I don't think sorting on multiple columns is very initiative and b) we are limited by the list view angular control we are reusing from core)

There are a couple of things you could do though. To allow sorting on multiple props by default, you could create a [ResultColumn] that joins the two fields so that you can do a single sort operation on it. Not ideal, but it's something you can do now.

Secondly, and something that would likely fit your scenario better is to look at using Data Views https://umco.github.io/umbraco-fluidity/api/collections/list-view/#defining-data-views This would allow you to create multiple views of your data so you might have an "Approved" and "Unapproved" view that the editors can switch between. Then with this, you would only need the single sort on the created field as the view would already be filtered to just approved or unapproved.

Will leave this open, but I'll be considering the scope of this issue just to be about defining a default sort order over multiple fields. Sorting in the UI would then override this.

@Nicholas-Westby
Copy link
Contributor Author

That data view option does sound useful for my scenario. Thanks.

@Nicholas-Westby
Copy link
Contributor Author

The data view seems to work nicely. Thanks again for the recommendation. For others to reference, here's what I did:

// Configure the list view.
collection.ListView(listView =>
{

    // Configure the fields in the list view.
    listView.AddField(x => x.Active);

    // Add a view of the reviews that haven't been approved.
    listView.AddDataView("Not Yet Approved", x => !x.Active);

    // Add a view of approved reviews.
    listView.AddDataView("Already Approved", x => x.Active);

    // Add a view of all reviews.
    listView.AddDataView("All Reviews", null);

});

Seems like I can pass in null for the predicate to create the default view that displays all rows. I had initially tried x => true, which bombed out.

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