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

gridview group by column

3 Answers 161 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Angela
Top achievements
Rank 1
Angela asked on 11 Jan 2017, 07:19 PM
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

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 12 Jan 2017, 07:09 AM
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.
0
Angela
Top achievements
Rank 1
answered on 12 Jan 2017, 08:18 AM
Thanks for the reply. But I need those who do not have a team, do not group them, but represent them without grouping.
0
Dimitar
Telerik team
answered on 12 Jan 2017, 11:14 AM
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.
Tags
GridView
Asked by
Angela
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Angela
Top achievements
Rank 1
Share this question
or