How to ignore nulls in SortDescriptors?

5 posts, 0 answers
  1. Alan
    Alan avatar
    5 posts
    Member since:
    Oct 2017

    Posted 18 Apr 2019 Link to this post

    I have a ListView where I am trying to sort by three columns: NumRejected, DueDate, Number. I have three sort descriptors:

    MyListView.SortDescriptors.Add(
        new PropertySortDescriptor
        {
            PropertyName = "NumRejected",
            SortOrder = SortOrder.Descending
        }
    );

    MyListView.SortDescriptors.Add(
        new PropertySortDescriptor
        {
            PropertyName = "DueDate",
            SortOrder = SortOrder.Ascending
        }
    );

    MyListView.SortDescriptors.Add(
        new PropertySortDescriptor
        {
            PropertyName = "Number",
            SortOrder = SortOrder.Ascending
        }
    );


    This works until there is a null value for DueDate. What I'm trying to do is: if there is a null for DueDate don't apply that SortDescriptor, just move on to the next. So for example I have three results in the ListView with values in all columns, they get sorted by NumRejected first, then DueDate then Number. If I also have some results with no DueDate I want them to be sorted NumRejected then Number, ignoring the DueDate. These should be below the three with DueDates. 

    At the moment a null on DueDate is being treated as the lowest value for that column, so they are at the top of the list.

    I think a DelegateSortDescriptor might be the way to go, but I can't find any examples how to use that.
  2. Didi
    Admin
    Didi avatar
    363 posts

    Posted 22 Apr 2019 Link to this post

    Hi Alan,

    Thank you for the provided code.

    I have created a sample that shows how the RadListView DelegateSortDescriptor could be used. Also, please note that when the DelegateSortDescriptor is set to the RadListView the items should be compared. In this case I am not sure if the provided example could be useful, as I am not aware with the business object you have. Indeed you should implement a custom logic how the items can be compared when their value is null. I have left a comment in the project. Please check the MainPage.xaml.cs file for more details.

    Review the attached sample and let me know if I can assist with anything else. 

    Regards,
    Didi
    Progress Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. Nethra
    Nethra avatar
    1 posts
    Member since:
    Apr 2019

    Posted 25 Apr 2019 in reply to Didi Link to this post

    Please can you attach the sample.
  4. Lance | Manager Technical Support
    Admin
    Lance | Manager Technical Support avatar
    1180 posts

    Posted 26 Apr 2019 Link to this post

    Hi Nethra,

    I can confirm it's attached on my side, however, I can see that it is not appearing in the forum page (it should be directly beneath her response). I am reattaching Didi's project to this reply.

    If it doesn't work, I'll immediately open a private support ticket on your account and send it to you directly. don't worry, this ticket will not count towards your support ticket total.

    Regards,
    Lance | Technical Support Engineer, Principal
    Progress Telerik
    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 Feedback Portal and vote to affect the priority of the items
  5. Alan
    Alan avatar
    5 posts
    Member since:
    Oct 2017

    Posted 29 Apr 2019 in reply to Lance | Manager Technical Support Link to this post

    Hi Didi, Lance,

    Thanks for the example project, that has helped me to fix my issue.

     

Back to Top