Custom Aggregate with Details Tables

3 posts, 0 answers
  1. bob
    bob avatar
    9 posts
    Member since:
    Oct 2008

    Posted 22 May 2012 Link to this post

    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
    End Sub
  2. Martin
    Martin avatar
    833 posts

    Posted 25 May 2012 Link to this post

    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,
    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.
  3. Michael
    Michael avatar
    3 posts
    Member since:
    Jul 2019

    Posted 21 May Link to this post

    This was what I was looking for. Thank you for sharing, it saved me many hours.
Back to Top