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

GroupBy Sorting

14 Answers 390 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 26 Jan 2009, 10:52 PM
Hello,

I am getting a list of objects such as this:

Category             Name                    Sequence
Category B           Something                    1    
Category B           Something                    2    
Category C           Something                    3    
Category A           Something                    4    
Category A           Something                    5    


When I do a Group By with the Category I get this:

Category: Category A
Category A           Something                    4    
Category A           Something                    5    

Category: Category B
Category B           Something                    1    
Category B           Something                    2    

Category: Category C
Category C           Something                    3    

My markup looks like this:

 

<GroupByExpressions>

 

 

<telerik:GridGroupByExpression>

 

 

<SelectFields>

 

 

<telerik:GridGroupByField HeaderText="Classification" FieldName="Classification.Name" ></telerik:GridGroupByField>

 

 

 

 

</SelectFields>

 

 

<GroupByFields>

 

 

<telerik:GridGroupByField FieldName="Classification.Name" SortOrder="None"></telerik:GridGroupByField>

 

 

</GroupByFields>

 

 

</telerik:GridGroupByExpression>

 

 

</GroupByExpressions>

 


Where Classification is my Category.

This is sorting the classifications in alphabetical order. I cannot get this to not happen this way. I want them to sort by the sequence that I pass it in. I have tried referenceing the sequence, this doesn't work. Please tell me how to get it to group by Category, but do not alphabetize them and do not show the sequence in the header as this will be a hidden column. Thanks.

Ultimately, I want it to end up like this:

Category: Category B
Category B           Something                    1    
Category B           Something                    2    

Category: Category C
Category C           Something                    3    

Category: Category A
Category A           Something                    4    
Category A           Something                    5    

Thanks,
Mike




14 Answers, 1 is accepted

Sort by
0
Mike
Top achievements
Rank 1
answered on 27 Jan 2009, 03:52 PM
Figured this out. What I do is sequence the groups with a number so, I now have this as my list:

Category             Name                    Sequence
Category B           Something                    1   
Category B           Something                    1    
Category C           Something                    2    
Category A           Something                    3    
Category A           Something                    3    

I then do this:

 

<GroupByExpressions>

 

 

<telerik:GridGroupByExpression>

 

 

<SelectFields>

 

 

<telerik:GridGroupByField HeaderText="Classification" FieldName="Classification.Name" SortOrder="None"></telerik:GridGroupByField>

 

 

</SelectFields>

 

 

<GroupByFields>

 

 

<telerik:GridGroupByField HeaderText="Sequence" FieldName="Classification.Sequence" SortOrder="Ascending"></telerik:GridGroupByField>

 

 

</GroupByFields>

 

 

</telerik:GridGroupByExpression>

 

 

</GroupByExpressions>

Notice in my GroupByFields, I am now grouping by Sequence instead of Classification. Which now gives me this:

Category: Category B
Category B           Something                    1    
Category B           Something                    1    

Category: Category C
Category C           Something                    2    

Category: Category A
Category A           Something                    3    
Category A           Something                    3    



0
Prakash Ghatage
Top achievements
Rank 1
answered on 26 Jun 2009, 03:23 PM
Hello,

I have a Radgrid and I am using GridGroupByExpression to enable my items to appear in one group and like this i have a sequence of Group with some items in each of it.

I am facing a similar issue, whenever I add some Group name in any order it gets sorted automatically alphabetically. I am not able to retain the order in which I enter my group name.

Is there any property by which we can set the Grid Group By Expression sorting to none and achieve the results that I want.

Group a:

Canada
Germany

Group: c
India
USA

Group d:

Finland

In the above example I have Grouped the Items under a,c,d and when I enter the Group names in any order they appear in alphabetical order.

Kindly help me in this regard.

Thanks in advance
Prashant
0
Nikolay Rusev
Telerik team
answered on 01 Jul 2009, 10:17 AM
Hello Prakash,

You cannot set sort order to none. Please refer to the following help article:
http://www.telerik.com/help/aspnet-ajax/telerik.web.ui-telerik.web.ui.gridgroupbyfield_properties.html

All the best,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Carl
Top achievements
Rank 1
answered on 01 Jul 2009, 12:10 PM
I had a similar issue the other day. I ended up doing all of my sorting and grouping in SQL and turned off grouping in the grid.  It was the ONLY way to get the result I needed, even with sorting set to none in the grid.

I loose the visual of the grouping and my totals by not having them grouped, but at least the sorting is what I need.


0
Billy
Top achievements
Rank 2
answered on 17 Sep 2009, 05:29 PM
I am having the same problem. Why does it change the sort when you group? There has to be a way to shut this off...
0
Princy
Top achievements
Rank 2
answered on 18 Sep 2009, 10:26 AM
Hello Billy,

It seems you can not turn off the default sorting when grouping in the grid but may be you can try the following suggestion:
Find out the column name based on which the grid is currently grouped by, in the GroupsChanging event of the grid, create your custom SortExpresion programmatically and then add that sort expression to the mastertable's SortExpressions collection. You can find more explanation on this in the following forum link:
Sorting a Grouped Grid

Hope this gets you started..
Princy.
0
Sam
Top achievements
Rank 1
answered on 21 Sep 2011, 09:16 AM
Hi Telerik Team,


I am facing a similar issue, whenever I add some Group name in any order it gets sorted automatically alphabetically.

My data:

Seq        EmpID           EmpName      CompanyName     DepartmentName

1             emp0001        Emp A            Company C            Department C1
2             emp0002        Emp B            Company C            Department C1
3             emp0003        Emp C            Company B            Department B1
4             emp0004        Emp D            Company A            Department A1    

Then I do a GroupBy with the CompanyName, I get this:

Seq                        EmpID                        EmpName                    DepartmentName
CompanyName: Company A
4                            emp0004                     Emp D                           Department A1 
CompanyName: Company B
3                            emp0003                     Emp C                           Department B1
CompanyName: Company C
1                            emp0001                     Emp A                           Department C1
2                            emp0002                     Emp B                           Department C1
  
RadGrid sorted automatically alphabetically by ComapnyName. I dont want the sorting to be done.
I want to display the data as it is in collection which i am binding to grid like this:

Seq                        EmpID                        EmpName                    DepartmentName
CompanyName: Company C
1                            emp0001                     Emp A                           Department C1
2                            emp0002                     Emp B                           Department C1
CompanyName: Company B
3                            emp0003                     Emp C                           Department B1
CompanyName: Company A
4                            emp0004                     Emp D                           Department A1 


Please help me to solve it! It is very urgent for me!

Thanks!
0
Sam
Top achievements
Rank 1
answered on 22 Sep 2011, 02:59 AM
Please help me!
0
Sam
Top achievements
Rank 1
answered on 26 Sep 2011, 02:56 AM
Kindly help me in this regard!

Thanks!
0
Sam
Top achievements
Rank 1
answered on 28 Sep 2011, 03:32 AM
There is noone can help me???
0
Nikita Gourme
Top achievements
Rank 1
answered on 28 Sep 2011, 08:45 AM
Sam, try the methods proposed by Princy and Nikolay, they are most likely the only ways to achive what you want.

0
Swathi
Top achievements
Rank 1
answered on 17 May 2013, 09:35 AM
Hi,

Below code is displaying Company name and ordered by Seq:


 <MasterTableView GroupLoadMode="Client" TableLayout="Fixed" DataKeyNames="DbrewId, NewsTitle">
                                <GroupHeaderItemStyle Font-Bold="true" />
                                <GroupByExpressions>
                                    <telerik:GridGroupByExpression>
                                        <SelectFields>
                                            <telerik:GridGroupByField HeaderText=" " HeaderValueSeparator="" FieldName="NewsGroupName" />
                                        </SelectFields>
                                        <GroupByFields>
                                            <telerik:GridGroupByField FieldName="Seq"></telerik:GridGroupByField>
                                        </GroupByFields>
                                    </telerik:GridGroupByExpression>
                                </GroupByExpressions>
                                <Columns>
                                    <telerik:GridTemplateColumn>
0
Nicolaï
Top achievements
Rank 2
answered on 31 Jul 2013, 08:27 AM
Protected Sub mygrid_GroupsChanging(ByVal sender As Object, ByVal e As GridGroupsChangingEventArgs) _
           Handles mygrid.GroupsChanging
           If e.Action = GridGroupsChangingAction.Group Then
               Dim sExpression As GridGroupByExpression = e.Expression
               sExpression.GroupByFields(0).SortOrder = GridSortOrder.Descending
           End If
       End Sub
0
Swathi
Top achievements
Rank 1
answered on 31 Jul 2013, 09:52 AM
Hi,

I fixed this issue by using "FieldName" property.  Please find the below code:

<telerik:GridGroupByExpression>
                                        <SelectFields>
                                            <telerik:GridGroupByField HeaderText=" " HeaderValueSeparator=" "  FieldName="NewsGroupName" />
                                        </SelectFields>
                                        <GroupByFields>
                                            <telerik:GridGroupByField FieldName="Seq" />
                                        </GroupByFields>
                                    </telerik:GridGroupByExpression>
                                </GroupByExpressions>
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Mike
Top achievements
Rank 1
Prakash Ghatage
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Carl
Top achievements
Rank 1
Billy
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Sam
Top achievements
Rank 1
Nikita Gourme
Top achievements
Rank 1
Swathi
Top achievements
Rank 1
Nicolaï
Top achievements
Rank 2
Share this question
or