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

Need Custom Sorting on Groups in RadGridView

5 Answers 442 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Arpit
Top achievements
Rank 1
Arpit asked on 29 Mar 2011, 07:51 AM
Hi,

I have a RadGridView grouped on a property of the binding object.

GroupDescriptor phaseDescriptor = new GroupDescriptor();
phaseDescriptor.Member = "PhaseName";
this.grdScope.GroupDescriptors.Insert(0, phaseDescriptor);

The collection of object bound to grid is "Task" with a property "PhaseName"

The Task object contains another property of type  "Phase" whose Name property is same as Task's PhaseName property.

The type Phase defines another property "Index". I want to sort the Groups according to this index. Right now I can only sort the groups ascending or descending based on PhaseName only.

Any ideas?

5 Answers, 1 is accepted

Sort by
0
Accepted
Yavor Georgiev
Telerik team
answered on 29 Mar 2011, 10:18 AM
Hi Arpit,

 There is a way you can achieve this using the generic GroupDescriptor which allows you to manually specify the grouping expression passed to the LINQ runtime. Here is what you need to do:
var descriptor = new GroupDescriptor<Task, Phase, int>();
descriptor.GroupingExpression = task => task.Phase;
descriptor.GroupSortingExpression = grouping => grouping.Key.Index;
descriptor.DisplayContent = "PhaseName";

 This creates a new GroupDescriptor that will be applied on a collection of Task objects, will group by the value of an expression returning a Phase type and will sort the groups by the value of an expression returning an integer (assuming that the Index property of the Phase type is of type int).

 Setting the DisplayContent property will determine the contents of the group descriptor item in RadGridView's group panel.

 Also, you might need to override the Phase type's ToString method and return the value of the Name property, because that will be displayed in the group row for each group in RadGridView.

 There's one small caveat - since you'll be grouping on a custom type, not string, your custom type needs to implement IEquatable<T>, since this will be used by LINQ to determine the number and composition of groups.

Kind regards,
Yavor Georgiev
the Telerik team
0
Arpit
Top achievements
Rank 1
answered on 29 Mar 2011, 10:44 AM
Thanks Yavor, I will try your idea.
-Arpit
0
Arpit
Top achievements
Rank 1
answered on 31 May 2011, 10:42 PM
Did exactly as you mentioned in the solution:

var serviceGroup = new Telerik.Windows.Data.GroupDescriptor<Task, Service, int>();
serviceGroup.GroupingExpression = task => task.ParentObject.ParentObject;
serviceGroup.GroupSortingExpression = group => group.Key.Index;
serviceGroup.SortDirection = System.ComponentModel.ListSortDirection.Ascending;
serviceGroup.DisplayContent = "ServiceName";
this.grdScope.GroupDescriptors.Insert(0, serviceGroup);
 
Type Service inherits IEquatable<Service>. But it also did not help. The groups in the gridview are still ordered in the sequence in which they were added to ItemSource.
0
Yavor Georgiev
Telerik team
answered on 01 Jun 2011, 08:25 AM
Hello Arpit,

 We discovered an issue a while back relating to how sorting is performed when the GroupSortingExpression is not the key of the IGrouping itself. Would it be possible to test your project against the Latest Internal Build assemblies?

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
Karan
Top achievements
Rank 1
answered on 24 Feb 2012, 12:48 PM
Hello, 

       I have a same case but i have a dictionary bound to the telerik grid. 
       I have a dictionary of "MyObject" which has two properties Category and CategoryOrder.
       I want to group the grid by Category and then sort items within a group by CategoryOrder.
var serviceGroup = new Telerik.Windows.Data.GroupDescriptor<KeyValuePair<int,MyObject>,string, int>();
serviceGroup.GroupingExpression = object => object.Category;
serviceGroup.GroupSortingExpression = group => object.CategoryOrder;

The grid never loads for me using above code... Any help would be greatful.. 
A custom descriptor would be nice too... if possible.
 
Tags
GridView
Asked by
Arpit
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Arpit
Top achievements
Rank 1
Karan
Top achievements
Rank 1
Share this question
or