Grid Group Footer Question

16 posts, 0 answers
  1. Alexander
    Alexander avatar
    2 posts
    Member since:
    Nov 2010

    Posted 07 Jan 2011 Link to this post

    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
  2. Mike Nogen
    Mike Nogen avatar
    34 posts
    Member since:
    May 2006

    Posted 07 Jan 2011 Link to this post

    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

     

     

     

     

     

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Alexander
    Alexander avatar
    2 posts
    Member since:
    Nov 2010

    Posted 07 Jan 2011 Link to this post

    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.
  5. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 13 Jan 2011 Link to this post

    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.
  6. Chris
    Chris avatar
    18 posts
    Member since:
    Apr 2009

    Posted 17 Feb 2011 Link to this post

    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.
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 18 Feb 2011 Link to this post

    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.
  8. Chris
    Chris avatar
    18 posts
    Member since:
    Apr 2009

    Posted 18 Feb 2011 Link to this post

    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>


  9. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 23 Feb 2011 Link to this post

    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!
  10. Eva
    Eva avatar
    19 posts
    Member since:
    May 2012

    Posted 04 Dec 2014 Link to this post

    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
  11. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 05 Dec 2014 Link to this post

    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.

     
  12. Eva
    Eva avatar
    19 posts
    Member since:
    May 2012

    Posted 05 Dec 2014 in reply to Radoslav Link to this post

    Dear Radoslav,

    my Telerik version does not support Group Header and Footer Templates.
    is there any other away?
  13. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 09 Dec 2014 Link to this post

    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.

     
  14. Eva
    Eva avatar
    19 posts
    Member since:
    May 2012

    Posted 09 Dec 2014 in reply to Radoslav Link to this post

    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.

  15. Radoslav
    Admin
    Radoslav avatar
    1564 posts

    Posted 11 Dec 2014 Link to this post

    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.

     
  16. Swetalana
    Swetalana avatar
    1 posts
    Member since:
    Feb 2016

    Posted 09 Feb Link to this post

    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

     

  17. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 12 Feb Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017