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

Group header showing item counts for user drag and drop grouping?

4 Answers 134 Views
Grid
This is a migrated thread and some comments may be shown as answers.
MARK
Top achievements
Rank 1
MARK asked on 04 Jan 2012, 08:37 PM
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

Sort by
0
Veli
Telerik team
answered on 06 Jan 2012, 11:22 AM
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
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
Veli
Telerik team
answered on 09 Jan 2012, 12:09 PM
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:

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!
Tags
Grid
Asked by
MARK
Top achievements
Rank 1
Answers by
Veli
Telerik team
MARK
Top achievements
Rank 1
Share this question
or