Custom Group Row based on column

7 posts, 1 answers
  1. Casey Watson
    Casey Watson avatar
    7 posts
    Member since:
    Feb 2009

    Posted 22 Jul 2009 Link to this post

    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!
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 28 Jul 2009 Link to this post

    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.
  3. DevCraft banner
  4. Casey Watson
    Casey Watson avatar
    7 posts
    Member since:
    Feb 2009

    Posted 28 Jul 2009 Link to this post

    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!
  5. Answer
    Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 29 Jul 2009 Link to this post

    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.
  6. Casey Watson
    Casey Watson avatar
    7 posts
    Member since:
    Feb 2009

    Posted 29 Jul 2009 Link to this post

    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!
  7. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 20 May 2010 Link to this post

    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 ?
  8. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 20 May 2010 Link to this post

    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.
Back to Top
DevCraft banner