I'd like to perform sorting/filtering on the data source level. How can I accomplish that? Can I subscribe to some events or provide some special collection view for this purpose?
Hello,
Thank you for your post. I have been looking into it and I suggest you use the following code:
ICollectionView collectionView = CollectionViewSource.GetDefaultView(data);
Where the “data” is an ObsevableCollection<T> e.g. and after you do that you can add SortDescriptions to the “collectionView” object and set it as a DataSource of the XamDataGrid. Please let me know if this helps you or you need further clarifications on this matter.
Looking forward for your reply.
Hi Stefan,
Thanks for your reply.
When saying "on the data source level" I meant that I need to perform sorting in the database. My application in this case is a classic 3-tier application where all my data operations, like sorting, grouping, paging must be delegated to data source layer. I don't want to do anything data-related "in memory". Out-of-the-box sorting of default CollectionView does not work for me.
I've tried implementing ICollectionView interface and supplying it as a data source for XamDataGrid. I was expecting that when I click any column in the grid for sorting, SortDescriptions collection in my ICollectionView would be modified and I could perform sorting through my data access layer and fill collection with new data. Unfortunately it seems like XamDataGrid does the sorting on its own (in memory) and SortDescriptions collection is never modified.
Looking forward for your support on this.
After some investigation I've partially figured out a solution.
For sorting I handled Sorting event of XamDataGrid and set e.Cancel = true to handle sorting on my own.
For filtering I handled RecordFilterChanging event and also set e.Cancel = true.
Anyway, there is still a problem with handling these features in a custom way but having default sorting/filtering UI displayed (for sorting a sort indicator in the label area and for filtering filter settings in filter record).
I created a separate thread for this here:
http://community.infragistics.com/forums/p/63907/323428.aspx#323428
As far as this thread is concerned, I'm marking it as resolved.