Display Detail Table Total Aggregates in the Parent Item of RadGrid Hierarchy

1 posts, 0 answers
  1. Eyup
    Eyup avatar
    11 posts
    Member since:
    Oct 2012

    Posted 02 Oct 2018 Link to this post

    Requirements


    Telerik Product and Version

    3.5+

    Supported Browsers and Platforms

    All browsers supported by Telerik UI for ASP .NET AJAX

    Programming language

    C#, JavaScript

    PROJECT DESCRIPTION

    This sample demonstrates a hierarchy grid with a calculated column in its master table, which displays the sum (or any other defined Aggregate as a matter of fact) of values in the detail tables. The logic happens within the boundaries of the mystical land of the ItemDataBound event:

    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridFooterItem && e.Item.OwnerTableView.Name == "DetailTableName")
        {
            GridFooterItem footerItem = e.Item as GridFooterItem;
            GridDataItem parentItem = footerItem.OwnerTableView.ParentItem;
     
            parentItem["Total"].Text = footerItem["Freight"].Text;
            footerItem.Display = false;
        }
    }

    Here is a video demonstrating the geekily satisfying result:
     


Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.