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

Group Sorting in gridview

5 Answers 78 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Perlom
Top achievements
Rank 1
Perlom asked on 29 Apr 2012, 07:19 PM
Hi,

I have Gridview that is abound to a collection of object “Benefit”, which has an Amount (decimal) that I would like to group on it is value. I have ranges with a text value that returns the corresponding range for that amount

Less than 100
100 – 250
250 – 500
Greater than 500

When I apply a group descriptor, the grouping occurs on these text vales, but it is sorted alphabetically. How can control the sorting of the group itself? I can convert that Range property to return integer value, but I still want to display the group text as above. I tried the Generic Group Descriptor <TElement, TKey, TSortKey> but didn’t help.

How can resolve this?

Cheers

5 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 30 Apr 2012, 08:55 AM
Hi,

 Have you checked this forum thread? Why using the Generic Group Descriptor <TElement, TKey, TSortKey> didn’t help ?

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Perlom
Top achievements
Rank 1
answered on 30 Apr 2012, 05:58 PM
Hi Didie,

Thank you for the reply. I actually have seen that thread, and I tried to follow it. However, Group Descriptor <TElement, TKey, TSortKey> resulted in groups of 1 element only, and the desiplayed name in the group panel was the Class long name (with name space).

Below is the code, I have property ApprovalRange which is string for the group name, and another property ApprovalSortRange which is an integer that I want to sort the group on (1 to 4). The colu,mn itself is amount which is decimal.

var disc = new GroupDescriptor<BenefitApprovalModelItem, BenefitApprovalModelItem, int> 
        { 
                GroupingExpression = item => item, 
                GroupSortingExpression = grouping => grouping.Key.ApprovalRangeSort, 
                DisplayContent = "ApprovalRange", 
                SortDirection = ListSortDirection.Ascending 
        };
0
Dimitrina
Telerik team
answered on 01 May 2012, 02:45 PM
Hello,

 You can override the ToString() method for the BenefitApprovalModelItem item to return the value that you want to appear in the group row. 

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Perlom
Top achievements
Rank 1
answered on 01 May 2012, 04:08 PM
Hi Didie,

That won’t help since the grouping itself is not right. This method resulted in all groups having 1 row only each!!! Is there anything wrong with the way I using that descriptor?
0
Dimitrina
Telerik team
answered on 01 May 2012, 04:40 PM
Hello,

 Indeed, it is like so. This is the expected behaviour though as you group by the entire item: GroupingExpression = item => item. You have to group on a property of the BenefitApprovalModelItem and set the type of the property as second type when the GroupDescriptor is defined. 

All the best,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Perlom
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Perlom
Top achievements
Rank 1
Share this question
or