Radgrid Header Totals

12 posts, 0 answers
  1. Carlos Quintero
    Carlos Quintero avatar
    13 posts
    Member since:
    Jul 2005

    Posted 10 Nov 2008 Link to this post

    Can you tell me the best way to show totals in a header on a Radgrid that is grouped?  I have a radgrid with 13 columns and grouped by only 1 column. I need the Group header(not the footer) to show the totals for each of the columns within the group and be aligned with each column.  Is this possible?  I have looked through all of the support sites and have had no luck. 

    Any help would be appreciated! 

    Thanks.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Nov 2008 Link to this post

    Hi Carlos,

    Have a look at the following help article and see if it helps.
    Performing calculations in group header

    Thanks
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Carlos Quintero
    Carlos Quintero avatar
    13 posts
    Member since:
    Jul 2005

    Posted 11 Nov 2008 Link to this post

    I had seen this article, but I need the calculations for each column to line up with the appropriate column and I don't believe this article does that.  Might you have any other suggestions?

     

    Thanks!

     

     

  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 11 Nov 2008 Link to this post

    Hi Carlos,

    One suggestion will be to create a Table with number of cells equal to the column number in the code behind. Calculate the totals for each column and assign the values to the corresponding tabe cells in the Table. Add the table to the GridGroupheader.

    Shinu
  6. Carlos Quintero
    Carlos Quintero avatar
    13 posts
    Member since:
    Jul 2005

    Posted 12 Nov 2008 Link to this post

    Any chance you have a sample project that does this?

    Thanks.

  7. Carlos Quintero
    Carlos Quintero avatar
    13 posts
    Member since:
    Jul 2005

    Posted 13 Nov 2008 Link to this post

    Do you have an example of this?
  8. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 14 Nov 2008 Link to this post

    Hello Carlos,

    Attached to this message, is a sample project, which demonstrates how to align the items in the group header.
    I hope it helps

    Sincerely yours,
    Yavor
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. Carlos Quintero
    Carlos Quintero avatar
    13 posts
    Member since:
    Jul 2005

    Posted 14 Nov 2008 Link to this post

    I am having some issues getting this to work.  I get the error "Conversion from string "Month1" to type 'Boolean' is not valid." when I run the project.  Month1 is one of the columns in my grid I am trying to total in the header.  Here is my code:

    Imports System.Data.SqlClient  
    Imports System  
    Imports System.Xml  
    Imports System.Data  
    Imports System.Drawing  
    Imports System.Web  
    Imports System.Data.OleDb  
    Imports System.Web.UI.WebControls  
    Imports System.Web.UI.HtmlControls  
    Imports System.Math  
    Imports Telerik.Web.UI  
     
     
     
    Partial Class _Default  
        Inherits System.Web.UI.Page  
        Dim reader As SqlDataReader = Nothing 
        Dim conn As SqlConnection = Nothing 
     
        Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemDataBound  
            If TypeOf e.Item Is GridGroupHeaderItem Then  
                Dim item As GridGroupHeaderItem = CType(e.Item, GridGroupHeaderItem)  
                Dim groupDataRow As DataRowView = CType(e.Item.DataItem, DataRowView)  
     
                'Clear the present text of the cell  
                item.DataCell.Text = "" 
                Dim column As DataColumn  
                For Each column In groupDataRow.DataView.Table.Columns  
                    If column.ColumnName = "cat" Then  
                        item.DataCell.Text += groupDataRow("cat").ToString  
     
                        'item.DataCell.Text += " " + CType(groupDataRow("total"), Decimal).ToString  
                    End If  
                Next column  
            End If  
     
            'If TypeOf e.Item Is GridDataItem Then  
            '    Dim item As GridDataItem = DirectCast(e.Item, GridDataItem)  
            '    If item("cat").Text = "Monthly App $" Then  
            '        item.ItemTy()  
            '        item.Font.Bold = True 
            '    End If  
            '    If item("product").Text = "Grand Total" Then  
            '        item.BackColor = Color.DarkSeaGreen  
            '        item.Font.Bold = True 
            '    End If  
            'End If  
        End Sub  
     
     
        Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource  
            RadGrid1.DataSource = getpipedata_grid1()  
            RadGrid1.MasterTableView.SortExpressions.AddSortExpression("id")  
        End Sub  
        Private Function getpipedata_grid1()  
            conn = New SqlConnection(SqlDataSource1.ConnectionString)  
            conn.Open()  
     
     
            Dim command As New SqlCommand("p_getdata", conn)  
            If RadComboBox1.SelectedValue = "Securities" Then  
                command.Parameters.Add(New SqlClient.SqlParameter("@channel", SqlDbType.VarChar)).Value = "Wach Secu" 
            Else  
                command.Parameters.Add(New SqlClient.SqlParameter("@channel", SqlDbType.VarChar)).Value = RadComboBox1.SelectedValue  
            End If  
            command.CommandType = CommandType.StoredProcedure  
            reader = command.ExecuteReader  
     
            Return reader  
     
        End Function  
     
        Protected Sub RadComboBox1_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles RadComboBox1.SelectedIndexChanged  
            RadGrid1.Rebind()  
        End Sub  
     
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
            If Not Page.IsPostBack Then  
                RadComboBox1.SelectedValue = "All" 
     
            End If  
        End Sub  
        Public Sub HideExpandColumnRecursive(ByVal tableView As GridTableView)  
            Dim nestedViewItems As GridItem() = tableView.GetItems(GridItemType.NestedView)  
            For Each nestedViewItem As GridNestedViewItem In nestedViewItems  
                For Each nestedView As GridTableView In nestedViewItem.NestedTableViews  
                    If nestedView.Items.Count = 0 Then  
                        Dim cell As TableCell = nestedView.ParentItem("ExpandColumn")  
                        cell.Controls(0).Visible = False 
                        nestedViewItem.Visible = False 
                    End If  
                    If nestedView.HasDetailTables Then  
                        HideExpandColumnRecursive(nestedView)  
                    End If  
                Next  
            Next  
        End Sub  
     
        Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.PreRender  
            HideExpandColumnRecursive(RadGrid1.MasterTableView)  
        End Sub  
     
        Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs)  
            If TypeOf e.Item Is GridGroupHeaderItem Then  
                TryCast(e.Item, GridGroupHeaderItem).DataCell.Visible = False 
                AddHandler e.Item.PreRender, AddressOf Item_PreRender  
            End If  
        End Sub  
     
        Private Sub Item_PreRender(ByVal sender As Object, ByVal e As EventArgs)  
            Dim text As String = DirectCast(sender, GridGroupHeaderItem).DataCell.Text  
            For i As Integer = 6 To DirectCast(sender, GridGroupHeaderItem).OwnerTableView.RenderColumns.Length - 1  
                Dim cell As New TableCell()  
                If DirectCast(sender, GridGroupHeaderItem).OwnerTableView.RenderColumns(i).UniqueName Then  
                    cell.Text = text 
                End If  
                DirectCast(sender, GridGroupHeaderItem).Cells.Add(cell)  
            Next  
        End Sub  
    End Class 
  10. Carlos Quintero
    Carlos Quintero avatar
    13 posts
    Member since:
    Jul 2005

    Posted 17 Nov 2008 Link to this post

    I just wanted to see if you can provide some assistance on the above post? 

    Thanks so much.

  11. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 18 Nov 2008 Link to this post

    Hello Carlos,

    Based on the supplied code snippet, it is hard to pinpoint the cause of the problem. If the error persists, you can open a formal support ticket, and provide a small working sample, which I can debug locally, and provide more information.

    Kind regards,
    Yavor
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  12. Jaicon
    Jaicon avatar
    3 posts
    Member since:
    Feb 2016

    Posted 03 Feb Link to this post

     This work fine for me

    protected void RadGrid1_PreRender(object sender, EventArgs e)
            {
                foreach (GridGroupFooterItem groupFooter in RadGrid1.MasterTableView.GetItems(GridItemType.GroupFooter))
                {
                    string value = groupFooter["uniqueName"].Text;
     
                    foreach (GridGroupHeaderItem groupHeader in RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader))
                    {
                        if (groupHeader.GroupIndex == groupFooter.GroupIndex)
                        {
                            groupHeader.DataCell.Text += " " + value;
                        }
                    }
                }
            }

  13. Eyup
    Admin
    Eyup avatar
    3012 posts

    Posted 08 Feb Link to this post

    Hello Jaicon,

    Thank you for sharing approach with our community. You can also check the following posts:
    http://www.telerik.com/forums/grid-group-by-expression-need-row-count-with-nested-radgrid#ZZ3HXO07cE-e9rrJ3p9CSA
    http://www.telerik.com/forums/item-counts-in-group-headers-with-multiple-groups#mVbMOzt0N06Xd7k9DCR-pA

    Regards,
    Eyup
    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