# Grouping Overview

**RadGrid** supports grouping of items based on the value of a particular column. You can even have multilevel grouping based on different criteria.

To group the data in a grid, specify grouping criteria by setting the **GroupByExpressions** property of a table view in the grid. You can set the group-by expressions [declaratively](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/functionality/grouping/group-by-expressions/declarative-definition) at design time, or [programmatically](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/functionality/grouping/group-by-expressions/programmatic-definition) in the code-behind.

## GridGroupPanel

To facilitate grouping, a special area called the **GridGroupPanel** can be displayed at the top of the grid to display grouping options. To display the group panel, set the grid's **ShowGroupPanel** property to **True**. When a table view is grouped, all group fields appear in this group panel as elements along with an icon that indicates the sort order:
![RadGrid group panel](https://www.telerik.com/products/aspnet-ajax/documentation/assets/95cc9ff0b38b366ed3a94b015b755c23/grd_grouppanel.png)

You can access the group panel using the grid's **GroupPanel** property. You can use **PanelStyle** and **PanelItemsStyle** to control the style of the group panel and its items.

You can also specify the position of the **GroupPanel** by setting the	**GroupPanelPosition** property of the grid. The available options for	the **GroupPanel** positions are: **Top**, **BeforeHeader** and	**Bottom**. The following screenshots illustrate the different rendering with those options:

**GroupPanelPosition - Top**
![RadGrid group panel above the header](https://www.telerik.com/products/aspnet-ajax/documentation/assets/a2fe81dd80ddbe2615d4d58798c7223d/radgrid-grouppanel-top.png)

**GroupPanelPosition - BeforeHeader**
![RadGrid group panel before the header](https://www.telerik.com/products/aspnet-ajax/documentation/assets/10b42b795a812290e237b148b57ef14c/radgrid-grouppanel-beforeheader.png)

**GroupPanelPosition - Bottom**
![RadGrid group panel below the header](https://www.telerik.com/products/aspnet-ajax/documentation/assets/b0451ddc859bf57256ab1ed8d16645cb/radgrid-grouppanel-bottom.png)

Users can use the sort indicator of the items in the group panel to specify the sort order of the grouping field.

Optionally, you can let users add sorting fields and rearrange the existing ones by dragging and dropping column headers onto the group panel or allow ungroup option for group panel items by setting the **GroupingSettings -> ShowUnGroupButton** property of the grid to true:
![Dragging a column header to the RadGrid group panel](https://www.telerik.com/products/aspnet-ajax/documentation/assets/ec41f13f8c21aa6313f489ba122b72b2/grd_group_dragheader.png)
![Ungroup option for group panel items](https://www.telerik.com/products/aspnet-ajax/documentation/assets/2c3c7bc79150b57017f299b2d44715a8/grd_ungroupbutton.png)

To allow users to change the grouping by dragging column headers, set the **ClientSettings.AllowDragToGroup** property to **True**. You can set this property at design time:

```ASP.NET
<telerik:RadGrid RenderMode="Lightweight" runat="server" ... />
   <ClientSettings AllowDragToGroup="True"/>
   ...
</telerik:RadGrid>
```

Alternatively, you can set the **AllowDragToGroup** property at runtime in the code-behind:

```C#
RadGrid RadGrid1 = new RadGrid();
RadGrid1.ClientSettings.AllowDragToGroup = true;
```

```VB
Dim RadGrid1 As RadGrid = New RadGrid
RadGrid1.ClientSettings.AllowDragToGroup = true			
```

## GridGroupSplitterColumn

When a table view is grouped, **RadGrid** automatically adds a special column (**GridGroupSplitterColumn**) that holds the buttons which let users expand and collapse groups of items:
![RadGrid group splitter column](https://www.telerik.com/products/aspnet-ajax/documentation/assets/71d52f8fb0d07f923aca181bc88c6a52/grd_groupsplittercolumn.png)

> note You can expand all groups on grid load by setting the **GroupsDefaultExpanded** property of the **MasterTableView** to **True** (this is the default value).

## Expand/Collapse all

RadGrid’s grouping structure has been extended with buttons in the group expand column headers that allow all group headerson a given level to be expanded/collapsed.The buttons in question are switched on through the **EnableGroupsExpandAll** property exposedboth on the level of the grid and the table views.

The new expand-all functionality supports all group load modes.

It is important to note that in the case of grouping for a given table view, the header expand-all buttons’ visibility dependson whether their preceding counterparts are visible and expanded. In other words, if, for example, the expand-all button for grouplevel 2 is collapsed/hidden then all expand-all buttons for the following group levels will be hidden.

When you have grouping and hierarchy combined in a common table view, the visibility of the hierarchy expand-all button depends on whether the expand-all button for the last group level is expanded/visible.

## See Also

* [Group-by expressions](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/functionality/grouping/group-by-expressions/declarative-definition)
* [Group footers](https://www.telerik.com/products/aspnet-ajax/documentation/controls/grid/functionality/grouping/group-footers)
