This is a migrated thread and some comments may be shown as answers.

Custom sorting with ICollectionView

20 Answers 625 Views
GridView
This is a migrated thread and some comments may be shown as answers.
hwsoderlund
Top achievements
Rank 1
hwsoderlund asked on 13 Jan 2009, 02:21 PM
I'm currently using MS datagrid bound against ObservableCollection implementing ICollectionView to solve the problem with custom sorting (as outlined here: http://weblogs.asp.net/manishdalal/archive/2008/12/30/silverlight-datagrid-custom-sorting.aspx )

Will the same technique work if I should decide to switch from the MS datagrid to RadGridView?

20 Answers, 1 is accepted

Sort by
0
Hristo Deshev
Telerik team
answered on 14 Jan 2009, 01:39 PM
Hi hwsoderlund,

Unfortunately no. RadGridView for WPF sniffs sort and group descriptions from the collection view it is bound to, and that will work for Silverlight too. We lack the reverse link though -- the grid will not add a sort or group description back to the original collection view.

Currently the recommended way to do custom sorting is via our SortingRequested event. We were discussing internally about improving our collection view sort/group/filter support, and we will be researching possible ways to do that in the future.

All the best,
Hristo Deshev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
hwsoderlund
Top achievements
Rank 1
answered on 14 Jan 2009, 02:41 PM
Ok. Is there a code example somewhere so I can see exactly how the SortingRequested  event works?
0
Hristo Deshev
Telerik team
answered on 15 Jan 2009, 05:11 PM
Hi hwsoderlund,

Oops! Forgot the link to the WPF example. Anyway, it uses an ADO.NET DataView and its built-in sorting capabilities and it is not a very good example for a Silverlight component.

To make amends, I have been playing with the dynamic LINQ query library and I've created a custom sorting example that uses the info passed through the SortingRequested event to sort the original data source. I am attaching the sample project.

All the best,
Hristo Deshev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Nik
Top achievements
Rank 1
answered on 26 May 2009, 07:06 PM
Hi I am working on Telerik Q1 09 release 2009.1.413.1020. I am working on the VB Language.

Can you please provide code snippet for this.

Prompt reply would be appreciated.




0
Vlad
Telerik team
answered on 27 May 2009, 08:45 AM
Hi Nik,

You can use our powerful converter to convert desired C# code to VB. VB version of Dynamic LINQ can be found here: http://msdn.microsoft.com/en-us/bb964686.aspx.

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
John Carr
Top achievements
Rank 1
answered on 21 Sep 2009, 11:43 PM
I'm not able to find the SortingRequestedEvent. Has this changed?
0
Milan
Telerik team
answered on 23 Sep 2009, 11:56 AM

Hi John Carr,

RadGridView now has two events that are related to sorting - the first one is called Sorting (almost identical to SortingRequested) and it is fired just before the grid is sorted; the seconds one is called Sorted and it is fired after the sorting is completed.

In case you would like to cancel a sorting request you just have to set the Canel property to true :

void gridView_Sorting(object sender, GridViewSortingEventArgs e)  
{  
    e.Cancel = true;  

Kind regards,

Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
John Carr
Top achievements
Rank 1
answered on 23 Sep 2009, 03:31 PM
Thanks, I did find these also.  
I have 2 issues related to sorting on the Silverlight gridview that I'm trying to work through and would appreciate any help.
1. We do sorting on the server so I want to cancel the sorting event, exactly as your example shows however the grid still sorts
2. I am setting the sortDescriptors to the correct column and direction then adding that to the grid, but the icon never appears in the header of the column. I looked at the examples in the controls demo, and I'm following that example as accurately as possible. Am I missing a property setting?

Any help will be greatly appreciated.

Ps: I'm adding the columns to the grid dynamically at runtime.
Running the latest 2009 Q2 Sp1
0
Milan
Telerik team
answered on 24 Sep 2009, 08:25 AM
Hi John Carr,

When you are using custom sorting you should not add items to the SortDescriptors collection because that triggers the built-in sorting. Your code should look something like that:

void gridView_Sorting(object sender, GridViewSortingEventArgs e)  
{  
    if (e.SortingState == SortingState.None)  
    {  
        e.SortingState = SortingState.Ascending;  
        this.gridView.ItemsSource = this.GetSortedData(e.SortPropertyName, "ASC");  
    }  
    else if (e.SortingState == SortingState.Ascending)  
    {  
        e.SortingState = SortingState.Descending;  
        this.gridView.ItemsSource = this.GetSortedData(e.SortPropertyName, "DESC");  
    }  
    else 
    {  
        this.gridView.ItemsSource = this.GetData();  
        e.SortingState = SortingState.None;  
    }  
 
    e.Cancel = true;  


Sincerely yours,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Anderson
Top achievements
Rank 1
answered on 06 Aug 2010, 07:48 PM
Has this changed at all?  This limits the usefulness of the RadGridView in MVVM scenarios.  If you aren't setting the Filter / Sorting properties on a CollectionView, how are we supposed to access these from a ViewModel?
0
Vlad
Telerik team
answered on 09 Aug 2010, 07:01 AM
Hello,

 Generally simple CollectionView is a bit limited if you want to store RadGridView settings like grouping and filtering. Why not use QueryableCollectionView instead CollectionView?

Best wishes,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Anderson
Top achievements
Rank 1
answered on 09 Aug 2010, 08:58 PM
I prefer not to have my ViewModel determine what view objects my view can have.  A Telerik.Widows.Data.QueryableCollectionView limits those options.

Is there a way to get the RadGridView to update the Filter property in a Two-Way manner?
0
Vlad
Telerik team
answered on 10 Aug 2010, 06:43 AM
Hello,

 I'm not sure how QueryableCollectionView limits you since the collection is not generic. Can you explain?
The grid filtering is complex hierarchical structure however ICollectionView Filter is just a predicate. 

Best wishes,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Anderson
Top achievements
Rank 1
answered on 10 Aug 2010, 04:02 PM
I'm completely wrong here.  I just noticed that this type implements ICollectionView, which would make it useful beyond just the Telerik controls.  Thanks for setting me straight.  It'd be nice not to have to do this, but it is nice to have at least an option and have it compatible with MVVM.  I'll give this a shot and see how it goes.  Thanks.
0
Alex
Top achievements
Rank 1
answered on 13 Oct 2010, 01:55 AM
Hi,

I'm just wondering if this has changed yet?
i.e. Does the RadGridView automatically add to the ICollectionView's SortDescriptionCollection collection?
Or is this something I have to do manually with events?


As I've noticed it does tie in with the DomainDataSource, but I can not seem to get it to tie in with my custom collection (But I'm using a derived class of the SortDescriptionCollection
i.e.:
#region ICollectionView Members
private CustomSortDescriptionCollection sortDescriptions = new CustomSortDescriptionCollection();
        public SortDescriptionCollection SortDescriptions { get { return sortDescriptions; } }

(The only thing my CustomSortDesciption really does is exposes new PUBLIC CollectionChanged notification, and bubbles the base sortdescriptioncollection's changes)



*edit*
I tried swapping my private backing field with just a regular sort desc collection
I've noticed the Grid view is "get"ing the sort descriptions, but it is still not adding to them
0
Yavor Georgiev
Telerik team
answered on 18 Oct 2010, 12:56 PM
Hello Alex,

 Would it be possible for you to open a support ticket and send us your application so that we may debug this behavior, please?

Kind regards,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alex
Top achievements
Rank 1
answered on 18 Oct 2010, 11:07 PM
Before I open a support ticket, can I just ask, is the ICollectionView's SortDescriptorCollection supposed to get updated? (Or is that something I have to do manually?)
0
Yavor Georgiev
Telerik team
answered on 19 Oct 2010, 12:11 AM
Hello Alex,

 When the GridView's ItemsSource implements ICollectionView, the GridView should manipulate its source's SortDescriptions collection as the user performs sorting. That is to say, it should all be automatic. There must be a problem somewhere for this not to work, thus we need to debug your application to discover the cause of this problem and fix it.

Kind regards,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alex
Top achievements
Rank 1
answered on 19 Oct 2010, 04:20 AM
Hi Yavor, I've submitted support ticket
358430

(The project will demonstrate the sort descriptors not working as mentioned in this post, and my placeholder problem in my other post)
0
Yavor Georgiev
Telerik team
answered on 19 Oct 2010, 01:05 PM
Hi Alex,

 Please check out my response to your question in the private support thread.

Kind regards,
Yavor Georgiev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
hwsoderlund
Top achievements
Rank 1
Answers by
Hristo Deshev
Telerik team
hwsoderlund
Top achievements
Rank 1
Nik
Top achievements
Rank 1
Vlad
Telerik team
John Carr
Top achievements
Rank 1
Milan
Telerik team
Anderson
Top achievements
Rank 1
Alex
Top achievements
Rank 1
Yavor Georgiev
Telerik team
Share this question
or