At runtime, when a user drag and drops any column they wish to group by, is there a way to show on the group header row, next to the label that says the column name, the count of items or rows that the group contains? I see in the examples how to use aggregation to show counts in the group header using declarative and programmatic methods but they all seem to apply to grouping that was declaratively or programmatically defined, not grouping defined by the user at runtime in an ad hoc manner.
4 Answers, 1 is accepted
0
Before you group by that column, there is no way RadGrid can know the data that will go into the group. Only after you drop a column header onto the group panel does RadGrid rebind and recalculate its groups. Thus, the count of items in the group is not known before grouping. If you externally calculate how many items each group would have based on the data, then you can display this information anywhere on the page, including inside the group panel using some javascript.
Veli
the Telerik team
Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0

MARK
Top achievements
Rank 1
answered on 06 Jan 2012, 06:53 PM
That's what I meant, is there a way after the user has dropped the column header and the rebind happens and the groups are recalculated that I can show the count in the group header for each group?
0
Accepted
Hi Mark,
In this case, you can programmatically modify the group expression that is created before the RadGrid is rebound. You can use the GroupsChanging event for that:
Greetings,
Veli
the Telerik team
In this case, you can programmatically modify the group expression that is created before the RadGrid is rebound. You can use the GroupsChanging event for that:
protected
void
RadGrid1_GroupsChanging(
object
sender, GridGroupsChangingEventArgs e)
{
if
(e.Action == GridGroupsChangingAction.Group)
{
if
(e.Expression.SelectFields.Count < 2)
{
e.Expression.SelectFields.Add(
new
GridGroupByField
{
FieldName = e.Expression.GroupByFields[0].FieldName,
FieldAlias =
"Items"
,
HeaderText =
"Items"
,
Aggregate = GridAggregateFunction.Count
});
}
}
}
The above event handler adds a Count aggregate to the group header for the newly created group.
Greetings,
Veli
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0

MARK
Top achievements
Rank 1
answered on 09 Jan 2012, 01:07 PM
That works great. Thank you!