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

RadGrid GroupByExpressions Sorting

13 Answers 422 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 2
Eric asked on 23 Mar 2011, 04:44 PM
Hi,

I have a RadGrid that gets its data from a stored procedure and the data is already ordered in the desired way. The RadGrid's group by automatically re-orders the group by field by alphabetical order. Is there a way to leave the order of the rows in its initial state? For example, if we're grouping on column X, if B appears before A from the data source, in the RadGrid B would be the first grouping section and A the second.

If not, then is there a way I can sort the group by field by a specific field? For example, this is what I would want to do:
<GroupByExpressions>
    <telerik:GridGroupByExpression>
        <SelectFields>
            <telerik:GridGroupByField FieldName="Category" SortField="ColumnXYZ" SortOrder="Ascending" />
        </SelectFields>
        <GroupByFields>
            <telerik:GridGroupByField FieldName="Category" />
        </GroupByFields>
    </telerik:GridGroupByExpression>
</GroupByExpressions>

Thanks in advance!

Eric

13 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 28 Mar 2011, 08:08 AM
Hi Eric,

To achieve the desired functionality you can handle the SortCommand event of the grid and there implement your logic. Find more information on custom grid sorting in the following resources:

http://www.telerik.com/help/aspnet-ajax/grdapplycustomsortcriteria.html
http://www.telerik.com/help/aspnet-ajax/grdsortingexpressions.html

I hope this gets you started properly.

Greetings,
Pavlina
the Telerik team
0
Dave
Top achievements
Rank 1
answered on 13 May 2011, 11:38 PM
0
Pavlina
Telerik team
answered on 16 May 2011, 08:18 AM
Hello Dave,

You can access the needed articles in the links below: 
http://www.telerik.com/help/aspnet-ajax/grid-apply-custom-sort-criteria.html
http://www.telerik.com/help/aspnet-ajax/grid-sorting-expressions.html

All the best,
Pavlina
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Dhamodharan
Top achievements
Rank 1
answered on 07 Apr 2014, 11:22 AM
Hi,
     I have a same requirement as Eric mentioned. I have multiple Group by Expressions. By default the group By expression is sorted by ascending order, but i have implemented order by Sequence in the retrieving query. i have also mentioned    <telerik:GridGroupByField FieldAlias="Desc" FieldName="Desc" SortOrder="None"></telerik:GridGroupByField>, but no use. By default it is order by Ascending order of the description.

I need a working solution as soon as possible. 
0
Princy
Top achievements
Rank 1
answered on 07 Apr 2014, 11:37 AM
Hi Dhamodharan,

SortOrder specifies how group values are sorted. Its value can be "Ascending" or "Descending". The default value of the SortOrder property is "Ascending". Setting it to "None" will not affect the order in which the group items are displayed.
Please take a look at this article to know more on Grid Group-by Expression.

Thanks,
Princy
0
Dhamodharan
Top achievements
Rank 1
answered on 07 Apr 2014, 01:45 PM
Hi Princy,
        Then what is the solution for my requirement, to be order by Sequence number, not in ascending order.
Example:
Apple       seq No- 2
       Unit 10
               Rate 35
Orange    seq No- 1
     Unit 20
               Rate 25
     Unit 10
              Rate 15

But Values need to be
 Orange      seq No- 1
     Unit 20
               Rate 25
     Unit 10
              Rate 15
 Apple         seq No- 2
       Unit 10
               Rate 35



0
Dhamodharan
Top achievements
Rank 1
answered on 07 Apr 2014, 04:42 PM
I need the sort order... in the <SelectFields> . I have declared as i mentioned, but it is not working.
<SelectFields>
            <telerik:GridGroupByField FieldAlias="Desc" FieldName="Desc" SortOrder="None">                                      </telerik:GridGroupByField>
</SelectFields>
0
Princy
Top achievements
Rank 1
answered on 08 Apr 2014, 05:50 AM
Hi Dhamodharan,

Setting SortOrder is not supported for the 'Select' fields in a 'Group By' expression. If you want to set SortOrder you have to set in the GroupByFields.

ASPX:
<telerik:GridGroupByExpression>
    <SelectFields>
        <telerik:GridGroupByField FieldAlias="SeqNo" FieldName="SeqNo"></telerik:GridGroupByField>
    </SelectFields>
    <GroupByFields>
        <telerik:GridGroupByField FieldName="SeqNo" SortOrder="Ascending"></telerik:GridGroupByField>
    </GroupByFields>
</telerik:GridGroupByExpression>

Thanks,
Princy
0
Peter Huisman
Top achievements
Rank 2
answered on 03 Jul 2014, 03:48 PM
Then why even allowing the None option as a standard if it doesn't do anything. In addition, it would be nice to have a valid None option so no extra programming is needed to avoid the automatic ordering by RadGrid.
0
Pavlina
Telerik team
answered on 08 Jul 2014, 06:18 PM
Hello Peter,

I am afraid that there is no way to remove the sorting of the Grouped data. The way the grouping functionality works is it first sorts the data and then it is grouping the data by given field. When the Grouping is performed for the Grid there is no way to understand currently grouped item in which place was before the grouping. And what about if the item was in such order that it now needs to be shown in another Group. This will break the functionality.

Another thing, when you want to perform grouping on a database level you are always forced to ORDER BY before GROUP BY. And we are also performing the grouping operation over the datasource.

Regards,
Pavlina
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Steve
Top achievements
Rank 1
answered on 03 Aug 2015, 08:31 PM

Searching the same issue and found this year old thread.  Coming from a sql server database perspective this workaround below worked for me. Basically provide a virtual unique value from your query for your grid to groupby and sort..but display a group name in the select (sql order by in the sql is ignored going to grid but left for you to observe the results).  The key here is the row_number() function that assign a value per record while sorting.

-- sql server,database query,  GroupSequence = unique group or sequence ID given at query time
select g.GroupSequence, g.GroupName, sp.SalesPersonID, sp.FirstName, sp.EmailAddress
from dbo.SalesPersons sp
inner join (select row_number() over(order by Sequence, [Description], SalesGroupID) as GroupSequence, SalesGroupID, Description as GroupName from  dbo.SalesGroups) g on g.SalesGroupID = sp.SalesGroupID                                                              
order by GroupSequence, FirstName    

<telerik:GridGroupByExpression>
    <SelectFields>
        <telerik:GridGroupByField FieldName="GroupName"></telerik:GridGroupByField>
    </SelectFields>
    <GroupByFields>
        <telerik:GridGroupByField FieldName="GroupSequence"></telerik:GridGroupByField>
    </GroupByFields>
</telerik:GridGroupByExpression>

 

 

 ‚Äč

0
Kiran
Top achievements
Rank 2
answered on 15 Oct 2018, 01:24 PM

Hi Pavlina,

I do not know if this is any different. I am bringing data in, in the order of My preference. I tried setting the sort order to None in the groupbyfield. My requirement is to have 'GENERAL" category on the top followed by others departments in ascending order. Please find the attached that shows how it is as of now. It has everything grouped by department in ascending order. I tried setting the sort order to none and so on but nothing seemed to work.

 

Thank you.

0
Tsvetomir
Telerik team
answered on 18 Oct 2018, 09:26 AM
Hi Kiran,

This question has already been discussed in a separate support thread. I suggest to continue the conversation there. The ticket title is "Grouping in order to get a specific record on the top rather than sorting order".

Feel free to let us know any additional comments.

Kind regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Eric
Top achievements
Rank 2
Answers by
Pavlina
Telerik team
Dave
Top achievements
Rank 1
Dhamodharan
Top achievements
Rank 1
Princy
Top achievements
Rank 1
Peter Huisman
Top achievements
Rank 2
Steve
Top achievements
Rank 1
Kiran
Top achievements
Rank 2
Tsvetomir
Telerik team
Share this question
or