gridview group by column

4 posts, 0 answers
  1. Angela
    Angela avatar
    2 posts
    Member since:
    Jan 2017

    Posted 11 Jan 2017 Link to this post

    Hi. First, thank you beforehand. I have a problem and I do not know how to do it. I have a gridview in which, through a query, I get results in a column of player names, and another column of teams. Each player can belong to a team, but there may be players who do not belong to any team. In my interface I have a button, which when I press it, should show me in my gridview a grouping in the first column of the players belonging to the same team. And those who do not have a team, do not group them into any group, that is, I put them for example down groups of teams formed by players.
    Could you tell me how to do this ???

    Example:
    Name           Team

    J1               TeamA
    J2               TeamB
    J3               TeamC
    J4               TeamA
    J5               TeamB
    J6
    J7
    J8               TeamC

    Result in my GridView: Push Button

         Name         Team
    +TeamA
          J1            TeamA
          J4            TeamA
    + TeamB
          J2             TeamB
          J5             TeamB
    + TeamC
         J3              TeamC
         J8              TeamC
    J6
    J7
  2. Dimitar
    Admin
    Dimitar avatar
    2949 posts

    Posted 12 Jan 2017 Link to this post

    Hello Angela,

    You just need to add a group descriptor to the grid:
    radGridView1.GroupDescriptors.Add("Team", ListSortDirection.Ascending);

    I hope this information is useful. Let me know if you need further assistance.

    Regards,
    Dimitar
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Angela
    Angela avatar
    2 posts
    Member since:
    Jan 2017

    Posted 12 Jan 2017 Link to this post

    Thanks for the reply. But I need those who do not have a team, do not group them, but represent them without grouping.
  4. Dimitar
    Admin
    Dimitar avatar
    2949 posts

    Posted 12 Jan 2017 Link to this post

    Hi Angela,

    You can hide the group row where the team is null:
    public RadForm1()
    {
        InitializeComponent();
        radGridView1.DataSource = GetTable();
        radGridView1.AutoExpandGroups = true;
         
     
        radGridView1.ViewRowFormatting += RadGridView1_ViewRowFormatting;
    }
     
    private void RadGridView1_ViewRowFormatting(object sender, Telerik.WinControls.UI.RowFormattingEventArgs e)
    {
        if (e.RowElement is GridGroupHeaderRowElement && ((object[])e.RowElement.RowInfo.Group.Key)[0] == null)
        {
            e.RowElement.RowInfo.Height = 1;
        }
         
    }

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top