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

Radgrid group totals for dynamic columns

9 Answers 349 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Filiz
Top achievements
Rank 1
Filiz asked on 29 Jul 2011, 03:07 PM

Radgrid columns preparing dynamically. Group code is:

 

 

 

Protected SubRadGrid1_ColumnCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles RadGrid1.ColumnCreated

 

If e.Column.DataType.Name = "Decimal" Or e.Column.DataType.Name = "Double" Then

        CType(e.Column, Telerik.Web.UI.GridBoundColumn).DataFormatString = "{0:N3}"

        CType(e.Column, Telerik.Web.UI.GridBoundColumn).Groupable = True

        CType(e.Column, Telerik.Web.UI.GridBoundColumn).Aggregate = Telerik.Web.UI.GridAggregateFunction.Sum
End If

End Sub


Group totals working fine if I use 1 group. When I create second a group 1th level sub total is not correct. For example:

SALARY DIVISION REGION
Region: AAA
Division : XXX
796,50 XXX AAA
796,50 XXX AAA
796,50 XXX AAA
2.389,50
Division : YYY
796,50 YYY AAA
796,5
1.593,00
Region: BBB
Division : LLL
3646,00 LLL BBB
3657,00 LLL BBB
3180,00 LLL BBB
3500,00 LLL BBB
13.983,00
3.500,00

 

9 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Aug 2011, 04:57 AM
Hello Filiz,

You can try the same approach in the following help documentation.Hope this helps.
Performing Calculations in Group Header.

Thanks,
Shinu.
0
Filiz
Top achievements
Rank 1
answered on 01 Aug 2011, 07:32 AM
Hello Shinu,
My problem is with group totals when I use 2 or more group. Group sub totals are not calculating correct. In my example, Region is main group and Division is 2nd group. Second group sub totals are correct but, for Region: AAA sub total must be 3982.5, but program is calculating 1593. For Region: BBB,  sub total must be 13983, but program is calculating 3500.



Thanks
Filiz
0
Tsvetina
Telerik team
answered on 04 Aug 2011, 09:54 AM
Hi Filiz,

As you can see in this demo, by default RadGrid performs its calculations correctly, no matter how many groups you use:
Group Footers

From the information provided, we cannot be sure what could be causing the problem on your side, so it would be good to post your grid declaration and data-binding logic, so we can look at them for possible mistakes as well.

All the best,
Tsvetina
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
Filiz
Top achievements
Rank 1
answered on 04 Aug 2011, 10:20 AM
Hi,
But in this demo columns are static. In my example, columns are creating dynamically. If columns are static, I don't have a problem. I have tried. Problems with dynamic columns. My code bloock is :

        Protected Sub RadGrid1_ColumnCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles RadGrid1.ColumnCreated

            If e.Column.DataType.Name = "Decimal" Or e.Column.DataType.Name = "Double" Then
                CType(e.Column, Telerik.Web.UI.GridBoundColumn).DataFormatString = "{0:N3}"

                CType(e.Column, Telerik.Web.UI.GridBoundColumn).Groupable = True
                CType(e.Column, Telerik.Web.UI.GridBoundColumn).Aggregate = Telerik.Web.UI.GridAggregateFunction.Sum
            End If

        End Sub

 

        Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
            Try
                dt = Getfieldsdata()
                Me.RadGrid1.MasterTableView.Columns.Clear()

                RadGrid1.DataSource = dt
                RadGrid1.DataBind()
                RadGrid1.Rebind()

            Catch ex As Exception
            End Try
        End Sub

 


0
Tsvetina
Telerik team
answered on 09 Aug 2011, 02:20 PM
Hi Filiz,

I would advise you to remove the databinding from the PreRender event handler. Additionally, you cannot use Rebind and DataBind at the same time. You should either bind the grid programmatically in the NeedDataSource event handler of RadGrid, or declaratively with a datasource control in order for grouping to work correctly.

Regards,
Tsvetina
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
Filiz
Top achievements
Rank 1
answered on 10 Aug 2011, 08:45 AM
Hi,
I have tried to use NeedDataSource event. Problem is same. This is last code for ColumnCreated event :
1.th level group totals are getting 2nd level group count (it must get 2nd level group record count). You can see this on attached images.

 

 

Protected Sub RadGrid1_ColumnCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles RadGrid1.ColumnCreated

If e.Column.ColumnType <> "GridExpandColumn" And e.Column.ColumnType <> "GridGroupSplitterColumn" Then

CType(e.Column, Telerik.Web.UI.GridBoundColumn).Groupable = True
CType(e.Column, Telerik.Web.UI.GridBoundColumn).Aggregate = Telerik.Web.UI.GridAggregateFunction.Count

End If

End Sub



0
Tsvetina
Telerik team
answered on 15 Aug 2011, 08:38 AM
Hi Filiz,

I tested your latest code and it works on my side. Can you try running the attached page and let me know how it behaves on your side?

Kind regards,
Tsvetina
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
Filiz
Top achievements
Rank 1
answered on 15 Aug 2011, 10:30 AM
Hi Tsvetina,
I tested your code and I added new columns for sample. You can see code files and screenshot. (Note: VS version is 2005 and Rad version is 2009.01.0311.20)



<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <br />
        <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowSorting="True"
            GridLines="None" PageSize="15" ShowFooter="True" ShowGroupPanel="True" Skin="Web20">
            <MasterTableView CellSpacing="-1" GroupLoadMode="Client" ShowGroupFooter="True">
            </MasterTableView>
            <ClientSettings AllowDragToGroup="True">
            </ClientSettings>
            <ExportSettings ExportOnlyData="True" FileName="DataExport" OpenInNewWindow="True">
            </ExportSettings>
        </telerik:RadGrid></div>
    </form>
</body>
</html>








Imports Telerik.Web.UI
Imports System.Data
Imports System.Data.SqlClient

Partial Class Default2
    Inherits System.Web.UI.Page

    Protected Sub RadGrid1_ColumnCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridColumnCreatedEventArgs) Handles RadGrid1.ColumnCreated
        If e.Column.ColumnType <> "GridExpandColumn" And e.Column.ColumnType <> "GridGroupSplitterColumn" Then
            CType(e.Column, Telerik.Web.UI.GridBoundColumn).Groupable = True
            CType(e.Column, Telerik.Web.UI.GridBoundColumn).Aggregate = Telerik.Web.UI.GridAggregateFunction.Count
        End If
    End Sub

    Protected Sub RadGrid1_NeedDataSource(ByVal [source] As Object, ByVal e As GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource
        Dim list As New ArrayList
        list.Add(New TestListItem("Item 0", 4, "00100", "01000"))
        list.Add(New TestListItem("Item 1", 1, "00100", "01000"))
        list.Add(New TestListItem("Item 2", 2, "00100", "02000"))
        list.Add(New TestListItem("Item 3", 3, "00100", "02000"))
        list.Add(New TestListItem("Item 4", 6, "00200", "02000"))
        list.Add(New TestListItem("Item 5", 2, "00200", "03000"))
        list.Add(New TestListItem("Item 6", 3, "00200", "03000"))
        list.Add(New TestListItem("Item 7", 1, "00200", "03000"))
        list.Add(New TestListItem("Item 8", 3, "00300", "03000"))
        list.Add(New TestListItem("Item 9", 5, "00300", "03000"))
        list.Add(New TestListItem("Item 10", 0, "00300", "04000"))
        RadGrid1.DataSource = CType(list, IEnumerable)
    End Sub

    Public Class TestListItem
        Private _a As String
        Private _b As Nullable(Of Integer)
        Private _aa As String
        Private _bb As String
        Public Sub New(ByVal a As String, ByVal b As Nullable(Of Integer), ByVal AA As String, ByVal BB As String)
            Me._a = a
            Me._b = b
            Me._aa = AA
            Me._bb = BB
        End Sub
        Public Property A() As String
            Get
                Return Me._a
            End Get
            Set(ByVal Value As String)
                Me._a = Value
            End Set
        End Property
        Public ReadOnly Property B() As Nullable(Of Integer)
            Get
                Return Me._b
            End Get
        End Property
        Public Property Division() As String
            Get
                Return Me._aa
            End Get
            Set(ByVal Value As String)
                Me._aa = Value
            End Set
        End Property
        Public Property Department() As String
            Get
                Return Me._bb
            End Get
            Set(ByVal Value As String)
                Me._bb = Value
            End Set
        End Property
    End Class

End Class

0
Tsvetina
Telerik team
answered on 18 Aug 2011, 08:54 AM
Hello Filiz,

This seems to be a problem with the version of RadControls. I tested the page with the changes you posted and got the correct results, as you can see both from the attached screenshot and if you run the project with the latest .dlls supporting .NET 2.0 (Q3 2010 SP2).

My advise is to upgrade your RadControls version in order to have this problem fixed. Otherwise you would most probably need to manually calculate and set the footer values.

Kind regards,
Tsvetina
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.

Tags
Grid
Asked by
Filiz
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Filiz
Top achievements
Rank 1
Tsvetina
Telerik team
Share this question
or