Sorting Groups

6 posts, 0 answers
  1. Konrad Radinger
    Konrad Radinger avatar
    6 posts
    Member since:
    Nov 2008

    Posted 09 Aug 2009 Link to this post

    Hi,

    I have a grid with 3 Cols: Player, Team, Points.
    When I group to Teams, it sums the point from each player to the team result.

    Now i want the best team on the first group and so on.

    How can I do that?

    Greetings

    Konrad
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 13 Aug 2009 Link to this post

    Hi Konrad Radinger,

    Thank you for your question. I am afraid that RadGridView does not support this functionality. We will consider your requirement. Write again if you have other questions.

    Kind regards,
    Victor
    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Simeon
    Simeon avatar
    3 posts
    Member since:
    Feb 2015

    Posted 03 Apr in reply to Victor Link to this post

    Bump

    Is this functionality now available?

  5. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 05 Apr Link to this post

    Hello Simeon,

    Thank you for writing.

    You can refer to the following help article demonstrating how to sort the group rows: http://docs.telerik.com/devtools/winforms/gridview/grouping/sorting-group-rows

    I hope this information helps. Should you have further questions I would be glad to help.

     Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Simeon
    Simeon avatar
    3 posts
    Member since:
    Feb 2015

    Posted 06 Apr in reply to Dess Link to this post

    Hi Dess, 

    Thank you for your replay.

    In my post i meant functionality described in first post because it exactly cover my requirements. As you can see in this post there is a grouping by Team (teamname) and want to sort by sum generated for the group by values in another column (points). In other words when i'm grouping by one column i want to use sorting based on aggregated values.

    In the help article you mentioned i can implement only sorting by values of grouped column, but not by aggregated values based on another column.

    If it is possible this functionality will make the grid very powerful in any case of custom reporting and so on.

    Regards,

    Simeon
  7. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 06 Apr Link to this post

    Hello Simeon,

    Thank you for writing back. 

    The custom GroupComparer gives you the opportunity to control how exactly the groups are sorted. You can find below a sample code snippet demonstrating a sample approach how to sort considering the team points:
    public Form1()
    {
        InitializeComponent();
     
        this.radGridView1.MasterTemplate.GroupComparer = new GroupComparer();
     
        List<Player> players = new List<Player>();
        for (int i = 1; i <= 10; i++)
        {
            players.Add(new Player("Player" + i, "Team" + i % 3, i - 1));
        }
        this.radGridView1.DataSource = players;
        this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
     
        GroupDescriptor descriptor = new GroupDescriptor();
        descriptor.GroupNames.Add("Team", ListSortDirection.Ascending);
        descriptor.Aggregates.Add("Sum(Points)");
        descriptor.Format = "{1} has {2} points.";
        this.radGridView1.GroupDescriptors.Add(descriptor);
    }
     
    public class GroupComparer : IComparer<Group<GridViewRowInfo>>
    {
        public int Compare(Group<GridViewRowInfo> x, Group<GridViewRowInfo> y)
        {
            if (((object[])x.Key).First().ToString().Contains("Team") && ((object[])y.Key).First().ToString().Contains("Team"))
            {
                decimal team1Points = 0m;
                decimal team2Points = 0m;
                foreach (GridViewRowInfo r in x)
                {
                    team1Points += (decimal)r.Cells["Points"].Value;
                }
                foreach (GridViewRowInfo r in y)
                {
                    team2Points += (decimal)r.Cells["Points"].Value;
                }
                return team1Points.CompareTo(team2Points);
            }
            
            return x.Key.ToString().CompareTo(y.Key.ToString());
        }
    }
     
    public class Player
    {
        public string PlayerName { get; set; }
     
        public string Team { get; set; }
     
        public decimal Points { get; set; }
     
        public Player(string playerName, string team, decimal points)
        {
            this.PlayerName = playerName;
            this.Team = team;
            this.Points = points;
        }
    }

    Note that this is just an example and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best.

    I hope this information helps. If you have any additional questions, please let me know.
    Regards,
    Dess
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready