RadGrid GroupByExpressions Sorting

12 posts, 0 answers
  1. Eric
    Eric avatar
    19 posts
    Member since:
    May 2009

    Posted 23 Mar 2011 Link to this post

    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

  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 28 Mar 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dave
    Dave avatar
    6 posts
    Member since:
    Jun 2010
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 16 May 2011 Link to this post

    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.

  6. Dhamodharan
    Dhamodharan avatar
    300 posts
    Member since:
    Sep 2010

    Posted 07 Apr 2014 in reply to Pavlina Link to this post

    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. 
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Apr 2014 in reply to Dhamodharan Link to this post

    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
  8. Dhamodharan
    Dhamodharan avatar
    300 posts
    Member since:
    Sep 2010

    Posted 07 Apr 2014 in reply to Princy Link to this post

    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



  9. Dhamodharan
    Dhamodharan avatar
    300 posts
    Member since:
    Sep 2010

    Posted 07 Apr 2014 in reply to Dhamodharan Link to this post

    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>
  10. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 08 Apr 2014 in reply to Dhamodharan Link to this post

    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
  11. Peter Huisman
    Peter Huisman avatar
    16 posts
    Member since:
    Dec 2004

    Posted 03 Jul 2014 Link to this post

    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.
  12. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 08 Jul 2014 Link to this post

    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.

     
  13. Steve
    Steve avatar
    1 posts
    Member since:
    Feb 2013

    Posted 03 Aug 2015 Link to this post

    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>

     

     

     ​

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017