This question is locked. New answers and comments are not allowed.
Clint Singer
Top achievements
Rank 1
Clint Singer
asked on 05 Nov 2009, 12:54 AM
Hi,
I was looking through the documentation (which appears to be for Q2) to see how to do custom sorting. It states that if I set e.Handled to true then the internal sorting would be skipped. In my experiment I have set e.Handled to true without actually changing anything else. I was expecting that the column wouldn't be sorted but it was.
Is this a bug?
Two other questions while I am at it...
How come the SortDescriptions or QueryableCollectionView don't take a Func<> containing left / right sorting code? It would seem that it would make custom sorting simpler while still taking advantage of the capabilities already in the system.
Is the filter window (the one that pops up when clicking the filter icon) sortable as well?
Perhaps an example would help with describing my needs. I have text columns that I wan't to be naturally sorted, ie. "Item 2" follows "Item 1" and not "Item 10". So I would like my column to be sorted either ascending or descending and then have the filter sorted the same way ascending.
Cheers,
Clint
I was looking through the documentation (which appears to be for Q2) to see how to do custom sorting. It states that if I set e.Handled to true then the internal sorting would be skipped. In my experiment I have set e.Handled to true without actually changing anything else. I was expecting that the column wouldn't be sorted but it was.
Is this a bug?
Two other questions while I am at it...
How come the SortDescriptions or QueryableCollectionView don't take a Func<> containing left / right sorting code? It would seem that it would make custom sorting simpler while still taking advantage of the capabilities already in the system.
Is the filter window (the one that pops up when clicking the filter icon) sortable as well?
Perhaps an example would help with describing my needs. I have text columns that I wan't to be naturally sorted, ie. "Item 2" follows "Item 1" and not "Item 10". So I would like my column to be sorted either ascending or descending and then have the filter sorted the same way ascending.
Cheers,
Clint
7 Answers, 1 is accepted
0
Clint Singer
Top achievements
Rank 1
answered on 05 Nov 2009, 01:38 AM
Hi,
To add to my previous post....
I found out how to use linq to produce a new IEnumerable which I should be able to assign to the RadGrid.ItemsSource, it looks as follows:
where NaturalComparer is of type Compare<string> and a.Id is a string.
When I run this code I get the following error on the line where items is assigned to grid.ItemsSource:
Could not load type 'System.Linq.OrderedEnumerable`2' from assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
The following code works fine and produces an IList<> which is properly populated and ordered without any exceptions.
Is this another bug in the Grid or am I doing something wrong with it?
Cheers,
Clint
To add to my previous post....
I found out how to use linq to produce a new IEnumerable which I should be able to assign to the RadGrid.ItemsSource, it looks as follows:
| if (e.SortPropertyName == "Name") |
| { |
| e.Handled = true; |
| var items = vm.MyItems.OrderBy(a => a.Id, new NaturalComparer()); |
| this.grid.ItemsSource = items; |
| } |
where NaturalComparer is of type Compare<string> and a.Id is a string.
When I run this code I get the following error on the line where items is assigned to grid.ItemsSource:
Could not load type 'System.Linq.OrderedEnumerable`2' from assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
The following code works fine and produces an IList<> which is properly populated and ordered without any exceptions.
| var lst = items.ToList(); |
Is this another bug in the Grid or am I doing something wrong with it?
Cheers,
Clint
0
Hello Clint,
The problem is that the type you create when you call OrderBy extension method is OrderedEnumerable, which is internal type. Unfortunately Silverlight did not provide a way to bind to internal types - calling ToList() is the only workaround. Hopefully Microsoft will change this for Silverlight 4.
Please check this demo for more info about custom sorting (you should use e.Cancel instead e.Handled) and for the filtering distinct values you can use our new DistinctValuesLoading event to provide your own values.
Regards,
Vlad
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.
The problem is that the type you create when you call OrderBy extension method is OrderedEnumerable, which is internal type. Unfortunately Silverlight did not provide a way to bind to internal types - calling ToList() is the only workaround. Hopefully Microsoft will change this for Silverlight 4.
Please check this demo for more info about custom sorting (you should use e.Cancel instead e.Handled) and for the filtering distinct values you can use our new DistinctValuesLoading event to provide your own values.
Regards,
Vlad
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
Clint Singer
Top achievements
Rank 1
answered on 06 Nov 2009, 12:14 AM
Hi,
Thanks for the reply. I am running into a problem with the custom sort. The NewSortingState is always "Ascending". Is there something I need to do to have it toggle between Ascending and Descending?
Cheers,
Clint
Thanks for the reply. I am running into a problem with the custom sort. The NewSortingState is always "Ascending". Is there something I need to do to have it toggle between Ascending and Descending?
Cheers,
Clint
0
Hello Clint,
Unfortunately I'm not sure what can cause this - can you send us an example where we can reproduce it?
Best wishes,
Vlad
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.
Unfortunately I'm not sure what can cause this - can you send us an example where we can reproduce it?
Best wishes,
Vlad
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
Terry
Top achievements
Rank 1
answered on 09 Dec 2009, 08:07 PM
So does this mean that any time you use an orderby in LINQ, the result cannot be bound to a RadGridView ItemsSource? It works fine with a standard Silverlight ListBox, so I consider this a serious bug in RadGridView.
0
Hello Terry,
Regards,
Vlad
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.
You can use OrderBy however you should call ToList() to avoid this exception. I've attached an example project for reference.
Regards,
Vlad
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
Terry
Top achievements
Rank 1
answered on 10 Dec 2009, 07:55 PM
Thanks, Vlad. That made things work.
Just as a rant regarding Microsoft, why would LINQ give you a collection of objects and then when you re-order the objects with an OrderBy, change the type of the collection?
... but since that is the case, I would recommend you modify your binding logic to accommodate this different object type in the future. It's disconcerting to have working code, add an OrderBy to the LINQ, and then have everything break. I spent a couple of hours tearing out my hair trying to resolve this.
In any event, I know the trick now, so on to the next issue!
Thanks,
Terry
Just as a rant regarding Microsoft, why would LINQ give you a collection of objects and then when you re-order the objects with an OrderBy, change the type of the collection?
... but since that is the case, I would recommend you modify your binding logic to accommodate this different object type in the future. It's disconcerting to have working code, add an OrderBy to the LINQ, and then have everything break. I spent a couple of hours tearing out my hair trying to resolve this.
In any event, I know the trick now, so on to the next issue!
Thanks,
Terry
