Telerik RadGrid supports grouping of items in a way similar to Microsoft OutlookA. You can even have multilevel grouping based on different criteria.
There is a special area at the top of the grid, in which the grouping options are displayed. This is the GridGroupPanel. When a TableView is grouped, all group fields appear in this GroupPanel as elements along with the sort order, e.g. Country, Order Date.
You can easily add more sorting fields and rearrange the existing ones by just dragging and dropping the header of the column you wish to use for grouping. For this purpose set AllowDragToGroup property to true.
| ASPX/ASCX |
Copy Code |
|
<rad:RadGrid runat="server" ... /> <ClientSettings AllowDragToGroup="True"/> |
And in the code-behind:
| C# |
Copy Code |
|
RadGrid RadGrid1 = new RadGrid(); RadGrid1.ClientSettings.AllowDragToGroup = true; ... |
| VB.NET |
Copy Code |
|
Dim RadGrid1 As RadGrid = New RadGrid RadGrid1.ClientSettings.AllowDragToGroup = true ... |
Once grouped, you can additionally sort the grid data, using the default sorting mechanism.
When a TableView is grouped, RadGrid automatically adds a special column - GridGroupSplitterColumn. It holds the expand/collapse buttons, used to expand/collapse all items that belong to a group.

When you want your data sorted and grouped, you need to provide the right expression syntax.
 |
Note: You can expand all groups on grid load by setting the GroupsDefaultExpanded property of the MasterTableView to true (this is the default value). |
Using Grouping with custom paging
There is no universal mechanism for grouping when custom paging is allowed. The reason for this is that with the custom paging mechanism you fetch only a part of the whole information from the grid data source. Thus, when the grouping event is triggered, the grid is restricted in operating with a limited subset of the entire available data and is not able to group the items accurately. Furthermore, the aggregate functions as Count, Sum, etc. (covering operations with the whole set of grid items) may return incorrect results.
Grouping with custom paging is still possible, but it has several limitations:
- The data that the grid binds to has to be sorted. If it is not, you may see different members of a group "grouped" to different pages when they appear at different locations in the data source.
- The aggregate functions will not work correctly for groups that span several pages. There is no way to calculate aggregate values for the entire group when we only work with a single page of data. It is best not to use aggregate functions at all when using grouping together with custom paging. If aggregates are important to you, reduce the data source size and disable custom paging.