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

Custom Group Row based on column

6 Answers 181 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Casey Watson
Top achievements
Rank 1
Casey Watson asked on 22 Jul 2009, 07:53 PM
I have a grid that displays records that have a ID property which identifies a group of records. The default view is to display all the individual records, but I have a button which groups them based on the ID property using the techniques discussed here (the ID column is not displayed to the user).  When the user groups the data using this method, I would like to display some summary data about the group on the group row. In the other cases, I would like to use the default grouping display.

Is there a way to use a style for a specific grouping or does the grid require you to override the template on a global basis?

Thanks!

6 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 28 Jul 2009, 10:58 AM
Hello Casey Watson,

Please  have a look at the attached example. It demonstrates a way to conditionally switch the template of the GridViewGroupRow.
You may set the Header property as demonstrated and you are not limited to text only , you can place whatever visual elements you need.

To see this in action just run the example and try the two buttons.
If you have any troubles adapting this to your project  don't hesitate to contact me .

Regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Casey Watson
Top achievements
Rank 1
answered on 28 Jul 2009, 02:28 PM
Pavel,

Thanks for the example.
 
This is close to what I was looking for, but I may not have explained the problem I am trying to solve clearly enough.
 
I would like to override the group row on a group basis only. In other words, say you click on the special grouping button in the example and then further group the data by age. The grid should display the special group row with summary information about the group (some examples of displaying aggregate information on this group row would be great!) but the age group should not display any other information other than what you get with the default template.

Example This would be grouped by ID and then Age using the example:

> Total Age: 59 Average Age: 29.5
   > 29
   > 30
> Total Age: 89 Average Age: 29.7
  > 29
  > 30
> Total Age: 30 Average Age: 30
  > 30

Is this possible?

Thanks again!
0
Accepted
Pavel Pavlov
Telerik team
answered on 29 Jul 2009, 01:29 PM
Hello Casey ,

Please see the sample attached. It is a modified version of the previous project with a few lines of c# added. I believe it gets us closer to the goal .

Here is the relevant code:


void RadGridView1_Grouping(object sender, Telerik.Windows.Controls.GridView.GridView.GridViewGroupingEventArgs e)  
        {  
            if ( e.GroupDescriptor.Member == "GroupID")  
                e.GroupDescriptor.AggregateFunctions.Add(new CountFunction("count","GroupID","place custom caption here"));  
        } 
This tells the RadGridView to add aggregate results in the group headers when the group is by "GroupID".

* To see this in action , just group by GroupID and then by Age  ( don't use the buttons ).



Let me know if I can help further.

Regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Casey Watson
Top achievements
Rank 1
answered on 29 Jul 2009, 02:43 PM
Thanks!

I think I can get this to work for what I need. It turns out that it was a lot easier that I thought.

Thanks again for the great support!
0
Marc Roussel
Top achievements
Rank 2
answered on 20 May 2010, 02:30 PM
If I group by C# code and not by draging a column on the form, the Grouping event is called but the GroupDescriptors is empty and it doesn't get into the Grouped event so How am I supose to add aggregates ?
0
Marc Roussel
Top achievements
Rank 2
answered on 20 May 2010, 02:36 PM
Ok here's the code I have working

GroupDescriptor GDDocNum = new GroupDescriptor() { DisplayContent = "DocNum", Member = "DocNum" };  
 
GDDocNum.AggregateFunctions.Add(new SumFunction() { Caption = "Total QtyMatPre. : ", SourceField = "QtyMatPre" });  
GDDocNum.AggregateFunctions.Add(new SumFunction() { Caption = "Total QtyTubes. : ", SourceField = "QtyTubes" });  
 

I understand now that if I group by code I should add my aggregates as well.  And I see that I have to add it to the group line
I want my totals to appear.  So this is working well.

I posted it in case people would need it.

by the way, CountFunction or SumFunction do not have any constructor accepting parameters.  I add to set my values as you see.
Tags
GridView
Asked by
Casey Watson
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Casey Watson
Top achievements
Rank 1
Marc Roussel
Top achievements
Rank 2
Share this question
or