Custom sorting with ICollectionView

21 posts, 0 answers
  1. hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 13 Jan 2009 Link to this post

    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?
  2. Hristo Deshev
    Admin
    Hristo Deshev avatar
    559 posts

    Posted 14 Jan 2009 Link to this post

    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.
  3. DevCraft banner
  4. hwsoderlund
    hwsoderlund avatar
    419 posts
    Member since:
    Aug 2006

    Posted 14 Jan 2009 Link to this post

    Ok. Is there a code example somewhere so I can see exactly how the SortingRequested  event works?
  5. Hristo Deshev
    Admin
    Hristo Deshev avatar
    559 posts

    Posted 15 Jan 2009 Link to this post

    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.
  6. Nik
    Nik avatar
    14 posts
    Member since:
    Jan 2007

    Posted 26 May 2009 Link to this post

    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.




  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 27 May 2009 Link to this post

    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.
  8. John Carr
    John Carr avatar
    2 posts
    Member since:
    Sep 2007

    Posted 21 Sep 2009 Link to this post

    I'm not able to find the SortingRequestedEvent. Has this changed?
  9. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 23 Sep 2009 Link to this post

    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.
  10. John Carr
    John Carr avatar
    2 posts
    Member since:
    Sep 2007

    Posted 23 Sep 2009 Link to this post

    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
  11. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 24 Sep 2009 Link to this post

    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.
  12. Anderson
    Anderson avatar
    16 posts
    Member since:
    Feb 2008

    Posted 06 Aug 2010 Link to this post

    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?
  13. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 09 Aug 2010 Link to this post

    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
  14. Anderson
    Anderson avatar
    16 posts
    Member since:
    Feb 2008

    Posted 09 Aug 2010 Link to this post

    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?
  15. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 10 Aug 2010 Link to this post

    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
  16. Anderson
    Anderson avatar
    16 posts
    Member since:
    Feb 2008

    Posted 10 Aug 2010 Link to this post

    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.
  17. Alex
    Alex avatar
    141 posts
    Member since:
    Mar 2010

    Posted 12 Oct 2010 Link to this post

    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
  18. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 18 Oct 2010 Link to this post

    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
  19. Alex
    Alex avatar
    141 posts
    Member since:
    Mar 2010

    Posted 18 Oct 2010 Link to this post

    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?)
  20. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 18 Oct 2010 Link to this post

    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
  21. Alex
    Alex avatar
    141 posts
    Member since:
    Mar 2010

    Posted 18 Oct 2010 Link to this post

    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)
  22. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 19 Oct 2010 Link to this post

    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
Back to Top
DevCraft banner