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

Grid Group Footer Question

15 Answers 351 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 07 Jan 2011, 10:37 PM
Hello,

I have the grid which has groups set programmatically , and that functionality works as needed, subtotals get calculated fine. The grid is fully dynamic. What I need to do, is to have text inside each group footer which would display field name or field value of that group. That text needs to be under the column where group field name is displayed. For example:

ClientID: 1
ProductID: 2
Test 1 10 50
Test 2 20 60
ProductID 2 Total: 30 110
ClientID 1 Total: 30 110

Thanks,
Alex

15 Answers, 1 is accepted

Sort by
0
Mike Nogen
Top achievements
Rank 1
answered on 07 Jan 2011, 10:47 PM
Hello!

Have you tried the Column property Aggregate to calculate the Sum? If so there is another property wich define the text.

Aggregate

 

="Sum" FooterText="My custom text"

/M

 

 

 

 

 

0
Alexander
Top achievements
Rank 1
answered on 07 Jan 2011, 10:54 PM
That text needs to be under group label all the way to the left, not where actual subtotal is. Also I need to show what that group is, ClientID etc.
0
Radoslav
Telerik team
answered on 13 Jan 2011, 10:06 AM
Hi Alexander,

Unfortunately the RadGrid does not support the desired functionality. However it could be achieved with some custom logic. You could try getting all group header items and all group footer items into the RadGrid's PreRender event and change the footer text manually. For example:
void RadGrid1_PreRender(object sender, EventArgs e)
    {
        GridItem[] headerItems = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader);
        GridItem[] footerItems = RadGrid1.MasterTableView.GetItems(GridItemType.GroupFooter);
 
        for (int i = 0; i < headerItems.Length; i++)
        {
            var text = (headerItems[i] as GridGroupHeaderItem).Cells[1].Text;
            (footerItems[i] as GridGroupFooterItem).Cells[3].Text = text + " Total:";
 
            for (int j = 4; j < (footerItems[i] as GridGroupFooterItem).Cells.Count; j++)
            {
                var sumText = (footerItems[i] as GridGroupFooterItem).Cells[j].Text;
                if (sumText != " ")
                {
                    sumText = sumText.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries)[1];
                    (footerItems[i] as GridGroupFooterItem).Cells[j].Text = sumText;
                }
            }
        }
    }

Also please note that this is not a supporter scenario.
Additionally I am sending you a simple example which demonstrates the mentioned approach above.

Greetings,
Radoslav
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Chris
Top achievements
Rank 1
answered on 18 Feb 2011, 04:20 AM
I have a similar issue and tried the above code (converted to VB)

This seems to work fine if I have one grouping, but if I am grouping on two or more columns it is not showing the footer text.  I also want to show text the in the total grid footer.
0
Princy
Top achievements
Rank 2
answered on 18 Feb 2011, 09:49 AM
Hello Chris,

I have tried the same code with grouping on multiple columns and it is working at my end. Can you please paste your code for further help?
The following code snippet shows how to add grid footer from code behind.

Vb.Net:
Private total As Integer = 0
Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs)
    For Each item As GridDataItem In RadGrid1.Items
        total += Convert.ToInt32(item("total").Text)
    Next
    Dim gridfooterItem As GridFooterItem = DirectCast(RadGrid1.MasterTableView.GetItems(GridItemType.Footer)(0), GridFooterItem)
    gridfooterItem("total").Text = "total is" & total
    'calculate total and display here
End Sub

Thanks,
Princy.
0
Chris
Top achievements
Rank 1
answered on 18 Feb 2011, 02:55 PM
Princy,

I have aggregates already setup on certain columns (I added those in RadGrid1_ColumnCreated).  That is working fine, so I do not need to do any sum, avg, etc. while doing the PreRender.  I am strictly looking to show a label in the first cell of the footer that has the Grouping value.  In Alex's example above, I just need to display Product 2 Total  and Client ID 1 Total in the proper footers, so I don't even need the For j loop code.

Here is my code-behind:

Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender
        Dim headerItems As GridItem() = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader)
        Dim footerItems As GridItem() = RadGrid1.MasterTableView.GetItems(GridItemType.GroupFooter)
 
        Dim GridFoot As GridItem() = RadGrid1.MasterTableView.GetItems(GridItemType.Footer)
        TryCast(GridFoot(0), GridFooterItem).Cells(0).Text = "<strong>Total</strong>"
 
        For i As Integer = 0 To headerItems.Length - 1
            Dim text = TryCast(headerItems(i), GridGroupHeaderItem).Cells(1).Text
            TryCast(footerItems(i), GridGroupFooterItem).Cells(3).Text = text
 
            For j As Integer = 4 To TryCast(footerItems(i), GridGroupFooterItem).Cells.Count - 1
                Dim sumText = TryCast(footerItems(i), GridGroupFooterItem).Cells(j).Text
                If sumText <> " " Then
                    TryCast(footerItems(i), GridGroupFooterItem).Cells(j).Text = sumText
                End If
            Next
        Next
    End Sub

The problem arises in the line in BOLD above.  footerItems(i) does not correspond to the appropriate footer for the header value the code is retrieving in the For loop.  For example, Client ID 1 is headerItems(0) and Product ID 2 is headerItems(1).  But when it comes to the footer for those headers, footeritems(0) is Product ID 2 and footeritems(1) is Client ID 1.  It is reversed, but it gets even more complicated when you have 3 grouping columns and more than just 1 Product and 1 Client.

Here is the code from the ASPX page:
<asp:TextBox ID="txtReportID" runat="server" Visible="false"></asp:TextBox>
    <telerik:RadGrid ShowGroupPanel="true" AutoGenerateColumns="True" ID="RadGrid1"
         AllowFilteringByColumn="False" AllowSorting="True"
        ShowFooter="True" runat="server" GridLines="Both" AllowPaging="true" EnableLinqExpressions="false">
        <PagerStyle Mode="NextPrevAndNumeric" />
        <MasterTableView ShowGroupFooter="true" AllowMultiColumnSorting="True" UseAllDataFields="true">
        </MasterTableView>
        <ClientSettings AllowDragToGroup="true" />
        <GroupingSettings ShowUnGroupButton="true" />
    </telerik:RadGrid>


0
Radoslav
Telerik team
answered on 23 Feb 2011, 12:31 PM
Hi Chris,

Like I said in my first post the solution provided in this case is not a supported scenario for the RadGrid and it is a custom solution. Also this code will work correctly only for RadGrid with one level of grouping. All other cases could not been handled appropriately because getting the cell which will be changed is hardcoded:
Dim text = TryCast(headerItems(i), GridGroupHeaderItem).Cells(1).Text
TryCast(footerItems(i), GridGroupFooterItem).Cells(3).Text = text

In your case you need to find which is the changed cell into the footerItems.Cells collection and assign it a value based on the value in header's cell. Also please note that for the different levels of grouping the cells are different.

I hope this helps.

All the best,
Radoslav
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Eva
Top achievements
Rank 1
answered on 04 Dec 2014, 02:18 PM
dear all,

i have exactly the same issue "group footer text needs to be under group label all the way to the left, not where actual subtotal is".my grid is  two level grouped and group footer of first level is not under the first level Groupheader.

is ther anyway to solve this?

thanks in advance,
Eva
0
Radoslav
Telerik team
answered on 05 Dec 2014, 08:30 AM
Hi Eva,

The RadGrid has built-in Group Header and Footer Templates which can help you in your case to build a custom footer item with needed alignment. On the following online documentation article you can find more information:
http://www.telerik.com/help/aspnet-ajax/grid-group-header-footer-templates.html

I hope this helps.

Regards,
Radoslav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Eva
Top achievements
Rank 1
answered on 05 Dec 2014, 01:11 PM
Dear Radoslav,

my Telerik version does not support Group Header and Footer Templates.
is there any other away?
0
Radoslav
Telerik team
answered on 09 Dec 2014, 08:01 AM
Hello Eva,

Which version of our control do you use?
Also I found that you did not have any downloads in your account, may I ask you from where do you download  the Telerik UI for ASP.NET AJAX dll?

Looking forward for your reply.

Regards,
Radoslav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Eva
Top achievements
Rank 1
answered on 09 Dec 2014, 02:13 PM
Dear Radoslav
i use version 2011.3.1115.35.
also i am a developer of a company that has your product so that's why you don't see any downloads from my account.

0
Radoslav
Telerik team
answered on 11 Dec 2014, 09:24 AM
Hello Eva,

I suggest you to upgrade to the latest version of our controls. Since 2011 we have fixed huge number of bugs into the RadGrid and included some performance optimizations.
Additionally I am sending you a simple example which demonstrates the desired functionality without using the templates.

I hope this helps.

Regards,
Radoslav
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Swetalana
Top achievements
Rank 1
answered on 09 Feb 2016, 11:33 AM

Hi ,

I have a grid  which is getting group by payment status(eg Paid ,Unpaid and Cancelled ).I am showing total of  2 columns i.e.  amount and tax amount in the footer.

In the Footer, I want to add only the Sum of  Paid and Unpaid not Cancelled one.

Please let me know if there is any to achieve this.

 

Thanks,

Sweta

 

0
Konstantin Dikov
Telerik team
answered on 12 Feb 2016, 06:21 AM
Hi Sweta,

For such custom calculation you should set "Custom" aggregate for the columns and handle the OnCustomAggregate event of the grid, where you need to manually calculate and set the total value. More information on this matter is available in the following articles:
Hope this helps.


Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Alexander
Top achievements
Rank 1
Answers by
Mike Nogen
Top achievements
Rank 1
Alexander
Top achievements
Rank 1
Radoslav
Telerik team
Chris
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Eva
Top achievements
Rank 1
Swetalana
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or