mattbrailsford / umbraco-fluidity

A fluent CRUD user interface generator for Umbraco
https://our.umbraco.org/projects/backoffice-extensions/fluidity/
Apache License 2.0
48 stars 40 forks source link

Sort by Multiple Columns #101

Open Nicholas-Westby opened 5 years ago

Nicholas-Westby commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

Nicholas-Westby commented 5 years ago

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.