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

Grouping Header Aggregates

1 Answer 111 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rob
Top achievements
Rank 1
Rob asked on 30 Jun 2011, 09:09 PM
I setup a header aggregate in a grouping but it seems to be coming up with the wrong sum total.  Screenshot attached.

Very strange that the footer aggregates come up with the right total, but the header doesn't.  Below is how I'm setting up the structure of the grid columns.

Private Sub BuildDataGrid(ByVal view As Views)
    Try
        Dim addColumn As Action(Of GridColumn) =
            Sub(column) BottomSection(Of TMGrid)("dgView").MasterTableView.Columns.Add(column)
 
        Dim addToGrouping As Action(Of GridColumn) =
            Sub(column)
                BottomSection(Of TMGrid)("dgView").MasterTableView.GroupByExpressions.Add(
                    New GridGroupByExpression(column)
                )
            End Sub
 
        With BottomSection(Of TMGrid)("dgView")
            .MasterTableView.Columns.Clear()
            .MasterTableView.GroupByExpressions.Clear()
 
            Select Case view
                Case Views.Daily
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "tl_date",
                        Function() "Date",
                        Function() False,
                        Function() "{0:MMMM d}",
                        Sub(column)
                            Dim grouping As New GridGroupByExpression()
 
                            Dim selectDate As New GridGroupByField()
                            selectDate.FieldName = "tl_date"
                            selectDate.FieldAlias = "tl_date"
                            selectDate.FormatString = TMGrid.SHORT_DATE_FORMAT
                            selectDate.HeaderText = "DATE"
                            selectDate.HeaderValueSeparator = ": "
 
                            Dim selectTotalHours As New GridGroupByField()
                            selectTotalHours.FieldName = "te_hours"
                            selectTotalHours.FieldAlias = "te_hours"
                            selectTotalHours.HeaderText = "TOTAL HOURS"
                            selectTotalHours.Aggregate = GridAggregateFunction.Sum
                            selectTotalHours.FormatString = TMGrid.HOURS
                            selectTotalHours.HeaderValueSeparator = ": "
 
                            Dim groupByDate As New GridGroupByField()
                            groupByDate.FieldName = "tl_date"
                            groupByDate.FieldAlias = "tl_date"
 
                            grouping.SelectFields.Add(selectDate)
                            grouping.SelectFields.Add(selectTotalHours)
                            grouping.GroupByFields.Add(groupByDate)
 
                            'grouping.Expression = "tl_date [Date], Sum(te_hours) TotalHours [Total Hours] Group By tl_date"
                            BottomSection(Of TMGrid)("dgView").MasterTableView.GroupByExpressions.Add(grouping)
                        End Sub
                    )
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "tc_name",
                        Function() "ACTIVITY",
                        AddressOf RequireSubactivity,
                        Nothing,
                        addToGrouping
                    )
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "tsc_name",
                        Function() "SUBACTIVITY"
                    )
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "te_desc",
                        Function() "DESCRIPTION"
                    )
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "te_hours",
                        Function() "HOURS",
                        Function() True,
                        Function() "<a href='{0}'>{0:#0.00}</a>",
                        Sub(column)
                            column.ItemStyle.HorizontalAlign = HorizontalAlign.Right
                            column.HeaderStyle.HorizontalAlign = HorizontalAlign.Right
                            column.FooterStyle.HorizontalAlign = HorizontalAlign.Right
                            column.Aggregate = GridAggregateFunction.Sum
                            column.FooterAggregateFormatString = "Total: {0:#0.00}"
                        End Sub
                    )
                Case Views.Monthly
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "tl_monthname",
                        Function() "Month",
                        Function() False,
                        Nothing,
                        addToGrouping
                    )
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "tc_name",
                        Function() "ACTIVITY",
                        AddressOf RequireSubactivity,
                        Nothing,
                        addToGrouping
                    )
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "tsc_name",
                        Function() "SUBACTIVITY"
                    )
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "te_desc",
                        Function() "DESCRIPTION"
                    )
                    If (Convert.ToInt32(ViewState("ReportingMode")) = TMTERMSOptions.TMTERMSReportingModes.Daily) Then
                        TMGrid.AddBoundColumn(
                            addColumn,
                            Function() "te_hours",
                            Function() "HOURS",
                            Function() True,
                            Function() "{0:#0.00}",
                            Sub(column)
                                column.ItemStyle.HorizontalAlign = HorizontalAlign.Right
                                column.HeaderStyle.HorizontalAlign = HorizontalAlign.Right
                                column.FooterStyle.HorizontalAlign = HorizontalAlign.Right
                                column.Aggregate = GridAggregateFunction.Sum
                                column.FooterAggregateFormatString = "Total: {0:#0.00}"
                            End Sub
                        )
                    Else
                        TMGrid.AddBoundColumn(
                            addColumn,
                            Function() "te_hours",
                            Function() "HOURS",
                            Function() True,
                            Function() "<a href='{0}'>{0:#0.00}</a>",
                            Sub(column)
                                column.ItemStyle.HorizontalAlign = HorizontalAlign.Right
                                column.HeaderStyle.HorizontalAlign = HorizontalAlign.Right
                                column.FooterStyle.HorizontalAlign = HorizontalAlign.Right
                                column.Aggregate = GridAggregateFunction.Sum
                                column.FooterAggregateFormatString = "Total: {0:#0.00}"
                            End Sub
                        )
                    End If
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "certified_message",
                        Function() "CERTIFICATION"
                    )
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "approved_message",
                        Function() "APPROVAL"
                    )
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "te_approved_hours",
                        Function() "APPROVED HOURS",
                        Function() "{0:#,##0.00}"
                    )
                Case Views.Annual
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "tl_year",
                        Function() "YEAR",
                        Function() False,
                        Nothing,
                        addToGrouping
                    )
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "tc_name",
                        Function() "YEAR / ACTIVITY",
                        AddressOf RequireSubactivity,
                        Nothing,
                        addToGrouping
                    )
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "tsc_name",
                        Function() "YEAR / ACTIVITY / SUBACTIVITY"
                    )
                    TMGrid.AddBoundColumn(
                        addColumn,
                        Function() "te_hours",
                        Function() "HOURS",
                        Function() "{0:#,##0.00}"
                    )
            End Select
        End With
    Catch ex As Exception
        Throw New Exception("BuildDataGrid procedure failed", ex)
    End Try
End Sub

1 Answer, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 05 Jul 2011, 02:34 PM
Hello Rob,

Please make sure that the RadGrid and its columns are created according to the Programmatic creation help topic.
Here you can see how to perform calculations in the group headers of a grouped RadGrid.

I hope this helps.

Kind regards,
Mira
the Telerik team
Register for the Q2 2011 What’s New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
Tags
Grid
Asked by
Rob
Top achievements
Rank 1
Answers by
Mira
Telerik team
Share this question
or