An example for OrderByThenBy extension method in the ObservableCollectionView class

Oct 13, 2014 at 4:05 AM
Hi

I would like to get your help regarding the OrderByThenBy extension method in the ObservableCollectionView class

I have following class.
Class Customer 
{
   public int Id;
   public string Name;
   public string CompanyName;  
}


Customers = new ExtendedObservableCollection<Customer>();
CustomerView = new ObservableCollectionView< Customer>(Customers);


// I can order the view on single field as below

CustomerView.Order = (cust => cust.Name);
But I would like to sort the View based on two fields.
Cannot work out how to use OrderByThenBy method.
CustomerView.OrderByThenBy(cust => cust.CompnayName, cust => cust.Name);
I can see that the method returns an IEnumerable but not sure how best to make use of this.
Tried looking for an example in the Unit Tests and this extension method does not seem to have a unit test.

Could you please provide us usage of OrderByThenBy method for ObservableCollectionView ?

Thanks in Advance
Coordinator
Oct 13, 2014 at 8:37 AM
Its currently not possible as the Order property is the first parameter of OrderBy... I think this should easily be implemented. Stay tuned.
Coordinator
Oct 19, 2014 at 4:12 PM
Hi, ive split up the ObservableCollectionView into ObservableCollectionViewBase, ObservableCollectionView and QueryObservableCollectionView... Please download the latest source code and try it out. You can set the Query property with any LINQ expression (you can use OrderByThenBy there...).

Please inform me if it works for you. Then ill create a new NuGet package version...
Coordinator
Oct 19, 2014 at 9:02 PM
NuGet version v2.3.15 with this change is now available...
Oct 23, 2014 at 5:27 AM
hi
I work with Vinod Srinivasan and we are trying to implement your suggestion but unable to get it right.
so can you please give us an example on how to use OrderByThenBy method on ObservableCollectionView. We need to use Filter property on ObservableCollectionView as well.
Coordinator
Oct 23, 2014 at 7:52 AM
Try something like this:
var source = new ObservableCollection<Person>();
var view = new QueryObservableCollectionView<Person>();
view.Query = items => items.Where(p => p.FirstName.Contains("a"))
    .OrderByThenBy(p => p.FirstName, p => p.LastName); 
Now just bind to view.
If the filter or order has changed, just change the Query property.