This is a migrated thread and some comments may be shown as answers.
How to ignore nulls in SortDescriptors?
4 Answers 20 Views
This is a migrated thread and some comments may be shown as answers.
Alan
Top achievements
Rank 1
Alan asked on 18 Apr 2019, 02:52 PM
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.

4 Answers, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 22 Apr 2019, 01:19 PM
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
0
Nethra
Top achievements
Rank 1
answered on 26 Apr 2019, 03:29 AM
Please can you attach the sample.
0
Lance | Manager Technical Support
Telerik team
answered on 26 Apr 2019, 05:45 PM
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
0
Alan
Top achievements
Rank 1
answered on 29 Apr 2019, 03:05 PM

Hi Didi, Lance,

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

 

Asked by
Alan
Top achievements
Rank 1
Answers by
Didi
Telerik team
Nethra
Top achievements
Rank 1
Lance | Manager Technical Support
Telerik team
Alan
Top achievements
Rank 1
Share this question
or