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

Radgrid Header Totals

11 Answers 657 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carlos Quintero
Top achievements
Rank 2
Carlos Quintero asked on 10 Nov 2008, 04:28 PM
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.

11 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Nov 2008, 05:25 AM
Hi Carlos,

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

Thanks
Shinu.
0
Carlos Quintero
Top achievements
Rank 2
answered on 12 Nov 2008, 12:01 AM

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!

 

 

0
Shinu
Top achievements
Rank 2
answered on 12 Nov 2008, 05:46 AM
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
0
Carlos Quintero
Top achievements
Rank 2
answered on 12 Nov 2008, 06:33 PM
Any chance you have a sample project that does this?

Thanks.

0
Carlos Quintero
Top achievements
Rank 2
answered on 13 Nov 2008, 09:03 PM
Do you have an example of this?
0
Yavor
Telerik team
answered on 14 Nov 2008, 06:44 AM
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.
0
Carlos Quintero
Top achievements
Rank 2
answered on 14 Nov 2008, 03:42 PM
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 
0
Carlos Quintero
Top achievements
Rank 2
answered on 17 Nov 2008, 10:18 PM
I just wanted to see if you can provide some assistance on the above post? 

Thanks so much.

0
Yavor
Telerik team
answered on 18 Nov 2008, 06:50 AM
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.
0
Jaicon
Top achievements
Rank 1
answered on 03 Feb 2016, 05:37 PM

 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;
                    }
                }
            }
        }

0
Eyup
Telerik team
answered on 08 Feb 2016, 03:53 PM
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
Tags
Grid
Asked by
Carlos Quintero
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Carlos Quintero
Top achievements
Rank 2
Yavor
Telerik team
Jaicon
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or