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

[Solved] Sum of Grouped Items, not sum of all items in all groups?

3 Answers 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rich
Top achievements
Rank 1
Rich asked on 08 Apr 2009, 05:40 PM
Hi All,

I have a grid with a Grouped column. I want to display a COUNT of the groups in the footer.

Specifically i have a grid of invoices and i group them by customer. I want to show the number of unique customers in the footer.

<

 

telerik:GridBoundColumn DataField="fullName" Aggregate="Count" FooterText="Total Invoiced Members:" HeaderText="Name" SortExpression="fullName"

 

 

UniqueName="fullName">

 

 

</telerik:GridBoundColumn>

This seems to show a count of the invoices in the footer rather then a count of the "members". How can i get a count of the members?? Do i need to change the context of the query? thanks!

 


 

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 Apr 2009, 04:39 AM
Hi Rich,


To show the number of Groups in the footer you may try the following approach.

CS:
 
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridFooterItem) 
        { 
            int length = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader).Length; 
            GridFooterItem footer = (GridFooterItem)e.Item; 
            footer["ColumnUniqueName"].Text = length.ToString(); 
        } 
    } 


Try setting ShowGroupFooter property to true to show count in each Group footer.

ASPX:
 
<MasterTableView   ShowGroupFooter="true" > 
                 

Shinu
0
Rich
Top achievements
Rank 1
answered on 09 Apr 2009, 03:10 PM
Hey Thanks,

That's close except i'm really trying to show a COUNT for the entire query, this will give me the count for groups on the current page..

Any suggestions on how i can calculate the total count?

Thanks!
0
Shinu
Top achievements
Rank 2
answered on 15 Apr 2009, 09:57 AM
Hi Rich,

Give a try with the following approach in the PreRender event of the Grid and see whether it works.

CS:
 
 protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
       // initially remove paging 
        RadGrid1.MasterTableView.AllowPaging = false
        RadGrid1.MasterTableView.Rebind(); 
 
        //get the total Group count 
        int length = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader).Length; 
 
        //Enable paging for the Grid again 
        RadGrid1.MasterTableView.AllowPaging = true
        RadGrid1.MasterTableView.Rebind(); 
 
      // Set the footer text with the Total Group count 
       foreach (GridFooterItem footer in RadGrid1.MasterTableView.GetItems(GridItemType.Footer)) 
       { 
           footer["columnUniqueName"].Text = length.ToString(); 
       } 
 
    } 
 


Thanks
Shinu
Tags
Grid
Asked by
Rich
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Rich
Top achievements
Rank 1
Share this question
or