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

Sum of columns in GROUP FOOTERS

1 Answer 293 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Toni
Top achievements
Rank 1
Toni asked on 09 Apr 2015, 10:15 PM

I have a radgrid I am using to create what is essentially a dynamic crosstab where I create date columns across the top, based on calculations at runtime.  I know many of the column names at design and have tried both autogenerating columns and not.  Some columns i do not know until runtime (week start dates).  I'm trying to sum the number in those dynamically created week columns and having no luck.  What would be my best option??

 

my aspx: 

    <telerik:RadGrid ID="RadGrid1"  runat="server"  AllowSorting="True" AllowMultiRowSelection="false" AllowPaging="True" ShowGroupPanel="false" AutoGenerateColumns="false" GridLines="none" pagesize="500">
                     <MasterTableView ShowGroupFooter="true" UseAllDataFields="True">
                <GroupByExpressions>
                    <telerik:GridGroupByExpression>
                        <SelectFields>
                            <telerik:GridGroupByField FieldAlias="Team" FieldName="Team"  HeaderValueSeparator=": "></telerik:GridGroupByField>
                        </SelectFields>
                        <GroupByFields>
                            <telerik:GridGroupByField FieldName="Team" SortOrder="ascending"></telerik:GridGroupByField>
                        </GroupByFields>
                    </telerik:GridGroupByExpression>
                    <telerik:GridGroupByExpression>
                        <SelectFields>
                            <telerik:GridGroupByField FieldAlias="SkillRequired" FieldName="SkillRequired" HeaderValueSeparator=": "></telerik:GridGroupByField>
                        </SelectFields>
                        <GroupByFields>
                            <telerik:GridGroupByField FieldName="SkillRequired"></telerik:GridGroupByField>
                        </GroupByFields>
                    </telerik:GridGroupByExpression>
                </GroupByExpressions>
                <Columns>
                           
                </Columns>
            </MasterTableView>
            <ClientSettings ReorderColumnsOnClient="True" AllowDragToGroup="True" AllowColumnsReorder="True">
                <Selecting AllowRowSelect="True"></Selecting>
                <Resizing AllowRowResize="True" AllowColumnResize="True" EnableRealTimeResize="True"
                    ResizeGridOnColumnResize="False"></Resizing>
            </ClientSettings>
            <GroupingSettings ShowUnGroupButton="true"></GroupingSettings>
        </telerik:RadGrid>

 

 

 

My Code Behind:

 

   Protected Sub ProcessResources()
        'Add columns for the weeks between the to and from dates
        If IsDate([To].Text) And IsDate(From.Text) Then
            Dim MyRecords As DataSet = LoadResources([From].Text, [To].Text)
            Dim myWeeks As ArrayList = ReturnWeeks(From.Text, [To].Text)
            For i = 0 To myWeeks.Count - 1
                Dim myColumn As New DataColumn
                MyRecords.Tables("Resources").Columns.Add(myWeeks.Item(i))
                'changed columns to be autogenerated in order to attempt summation of hours 
                'Dim boundColumn As GridBoundColumn
                'boundColumn = New GridBoundColumn()
                'RadGrid1.MasterTableView.Columns.Add(boundColumn)
                'boundColumn.Aggregate = GridAggregateFunction.Sum
                'boundColumn.FooterText = "Sum of Hours:"
                'boundColumn.DataField = myWeeks.Item(i)
                'boundColumn.HeaderText = myWeeks.Item(i)
            Next
            'Iterate through myRecords and add hours where the task is in the range 
            Dim j As Integer
            For j = 0 To MyRecords.Tables("Resources").Rows.Count - 1
                Dim estimatedStart As Date = MyRecords.Tables("resources").Rows(j).Item("estimatedstartdate")
                Dim estimatedEnd As Date = MyRecords.Tables("resources").Rows(j).Item("estimatedenddate")
                Dim hours As Integer = MyRecords.Tables("resources").Rows(j).Item("esthours")
                Dim k As Integer
                For k = 0 To myWeeks.Count - 1
                    Dim weekstart As Date = myWeeks.Item(k)
                    Dim Weekend As Date = DateAdd(DateInterval.DayOfYear, 6, weekstart)
                    If estimatedStart <= Weekend And estimatedEnd >= weekstart Then
                        MyRecords.Tables("Resources").Rows(j).Item(weekstart) = hours
                    Else

                        MyRecords.Tables("Resources").Rows(j).Item(weekstart) = 0
                    End If

                Next
            Next
            MyRecords.Tables("Resources").Columns.Remove("EstimatedSTartDate")
            MyRecords.Tables("Resources").Columns.Remove("EstimatedEndDate")

            RadGrid1.DataSource = MyRecords.Tables("Resources")
            RadGrid1.DataBind()

End If
    End Sub

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 14 Apr 2015, 08:04 AM
Hi Toni,

First of all, please note that you should not use DataBind() to bind the grid, nor set its DataSource property outside the NeedDataSource event handler. Performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Exporting, Paging, Sorting, Filtering, etc. require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Advanced Data Binding

If you need to refresh the grid contents on an external action, e.g. Button click,
you can use the Rebind() method.

You can check the grid creation during Page_Init as demonstrated in the following section:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html#Section22

And closely follow the steps provided in this article for dynamically changing the columns structure:
http://www.telerik.com/help/aspnet-ajax/grid-changing-structure-dynamically.html

Finally, for displaying Totals you can use Aggregates provided by RadGrid:
http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/grouping/group-footers/defaultcs.aspx

Hope this helps.


Regards,
Eyup
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Grid
Asked by
Toni
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or