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

Custom Aggregate with Details Tables

2 Answers 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
bob
Top achievements
Rank 1
bob asked on 22 May 2012, 08:23 PM
I spent some time looking around for info on this and didn't find a good answer as to how to do this without having to use the detailstable databinding and databound events. In all the examples I found they all used the radgrid.MasterTableView.Items collection specifically. My solution turned out to be simpler by using e.Column.Owner.Items from the GridCustomAggregateEventArgs. By checking the e.Owner.Name that is set in the designer properties I can then tell which table that I'm trying to preform the custom Aggregate for and return different results.

In an effort to save others some time here, I'm posting some example code for this.

Protected Sub rg_CustomAggregate(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCustomAggregateEventArgs) Handles rg.CustomAggregate
 
    Dim i, j, k, l, m, n As Integer
    For Each di As GridDataItem In e.Column.Owner.Items
        If e.Column.Owner.Name = "MainTableName" Then
            'preform you custom aggregation calculations
            i += CType(di.GetDataKeyValue("maintablecolumn1"), Integer)
            j += CType(di.GetDataKeyValue("maintablecolumn2"), Integer)
            k += CType(di.GetDataKeyValue("maintablecolumn3"), Integer)
            e.Result = Decimal.Round(Convert.ToDecimal((i + j) / k * 100), 2)
        End If
        If e.Column.Owner.Name = "DetailTableName" Then
            l += CType(di.GetDataKeyValue("detailtablecolumn1"), Integer)
            m += CType(di.GetDataKeyValue("detailtablecolumn2"), Integer)
            n += CType(di.GetDataKeyValue("detailtablecolumn3"), Integer)
            e.Result = Decimal.Round(Convert.ToDecimal((i + j) / k * 100), 2)
        End If
    Next
End Sub

2 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 25 May 2012, 03:19 PM
Hello Bob,

Thank you for sharing your solution with our community. I am sure that it will help other developers implementing similar scenarios.

Kind regards,
Martin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Key
Top achievements
Rank 1
answered on 21 May 2020, 02:24 PM
This was what I was looking for. Thank you for sharing, it saved me many hours.
Tags
Grid
Asked by
bob
Top achievements
Rank 1
Answers by
Martin
Telerik team
Key
Top achievements
Rank 1
Share this question
or