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

MasterDetail Grid, Footer and Footer Text

4 Answers 121 Views
Grid
This is a migrated thread and some comments may be shown as answers.
wonderbison
Top achievements
Rank 1
wonderbison asked on 25 Jul 2011, 06:49 PM
Hi

I have a masterdetail grid with two group by expressions to group the data at 2 levels. All works well. However in the footer text of the row, I would like the value of the group by expression to be shown.

So at present it is something like this

This is my top header
This is my second header
RowData1 20 30 15 22
RowData2 12 11 9 15
RowData3 11 52 11 23
43 93 35 60
RowData4 156 11 22 347
156 11 22 347
199 104 57 407


What I want is this
This is my top header
This is my second header
RowData1 20 30 15 22
RowData2 12 11 9 15
RowData3 11 52 11 23
This is my second header 43 93 35 60
RowData4 156 11 22 347
This is my second header 156 11 22 347
This is my top header 199 104 57 407

And then when it collapses I would ideally like

This is my top header
This is my second header 43 93 35 60
This is my second header2 156 11 22 347
This is my top header 199 104 57 407

Help very much appreciated

Thanks

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Jul 2011, 05:43 AM
Hello,

You can try the same approach in the following help documentation to achieve this.
Declarative Definition.

Thanks,
Princy
0
wonderbison
Top achievements
Rank 1
answered on 26 Jul 2011, 08:09 AM
Hi

This doesnt solve my problem I am afraid as that the header text is static.

I need it to be dynamic with the value of the grouping. So I need the headertext (or group footer text) to be the value of the grouping and that the totals are under each of the columns as you see in the group footer

I attach some example code and a screen shot. In the screen shot you will see some "balloons" and those balloons contain the text that I want in the group footer. Ideally I would like it in the group header so that when the grid is collapsed I only have 1 row per grouping with the values but I understand the group footer aggregation functionality is not available in the groupheader.

The values are taken from the grouping value. The reason I need these are so that when the group is collapsed, I can see the totals and the grouping they relate to. If I could then hide the header when collapsing that would be even better

<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="DataFormatting._Default" %>
  
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
  
  
<form id="form1" runat="server">
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
</telerik:RadAjaxManager>
<telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
</telerik:RadScriptManager>
    <div class="contributionTable" >
        <asp:PlaceHolder ID="PlaceHolder1" runat="server" >
        <telerik:RadGrid ID="clientContribution" runat="server" 
            onitemdatabound="clientContribution_ItemDataBound" >
        </telerik:RadGrid>
        </asp:PlaceHolder>
    </div>
  
</form>


using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Diagnostics;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
  
namespace DataFormatting
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                BuildTheGrid();
            }
  
        }
        protected void clientContribution_ItemDataBound(object sender, GridItemEventArgs e)
        {
        }
        #region Build the grid
        private DataSet BuildTheGrid()
        {
            try
            {
  
                clientContribution.DataSource = null;
                DataSet contributionColumns = LoadGridData();
  
  
                // Define the main grid
                for (int loopPos = clientContribution.MasterTableView.Columns.Count; loopPos > 0; loopPos--)
                {
                    clientContribution.MasterTableView.Columns.RemoveAt(loopPos - 1);
                }
                clientContribution.ID = "MyGrid";
                clientContribution.DataSource = contributionColumns;
                clientContribution.Width = Unit.Percentage(98);
                clientContribution.AutoGenerateColumns = false;
                clientContribution.ShowStatusBar = true;
                clientContribution.GroupingEnabled = true;
                clientContribution.MasterTableView.ShowGroupFooter = true;
                clientContribution.GroupingSettings.RetainGroupFootersVisibility = true;
                clientContribution.MasterTableView.Width = Unit.Percentage(100);
  
                // now build the hierarchical grid
                GridGroupByExpression groupExpression = new GridGroupByExpression();
                clientContribution.MasterTableView.GroupByExpressions.Add(new GridGroupByExpression("GroupValue1 group by GroupValue1"));
                clientContribution.MasterTableView.GroupByExpressions.Add(new GridGroupByExpression("GroupValue2 group by GroupValue2"));
  
                GridBoundColumn boundColumn = new GridBoundColumn();
  
                foreach (DataColumn col in contributionColumns.Tables[0].Columns)
                {
                    boundColumn = new GridBoundColumn();
                    clientContribution.MasterTableView.Columns.Add(boundColumn);
                    boundColumn.DataField = col.ColumnName;
                    boundColumn.HeaderText = col.ColumnName;
                    boundColumn.Visible = true;
                    if (col.Ordinal > 1)
                    {
                        boundColumn.Aggregate = GridAggregateFunction.Sum;
                        boundColumn.FooterText = "";
                        boundColumn.DataFormatString = "{0:##,##0}";
                    }
  
                }
                clientContribution.DataBind();
            }
            catch (Exception exc)
            {
                Debug.WriteLine(exc.Message);
                return null;
            }
            finally
            {
            }
            return null;
  
        }
        #endregion
  
        #region Load the Grid Data
        private DataSet LoadGridData()
        {
            // return the data to display
            DataSet contributionData = new DataSet("MyData");
  
            DataTable gridData = contributionData.Tables.Add("ContData");
  
            gridData.Columns.Add(new DataColumn("GroupValue1"));
            gridData.Columns.Add(new DataColumn("GroupValue2"));
            DataColumn decCol = new DataColumn("ValueToSum");
            decCol.DataType = System.Type.GetType("System.Int32");
            gridData.Columns.Add(decCol);
            DataColumn perCol = new DataColumn("ValueToIgnore");
            perCol.DataType = System.Type.GetType("System.Int32");
            gridData.Columns.Add(perCol);
            DataColumn decCol2 = new DataColumn("ValueToSum2");
            decCol2.DataType = System.Type.GetType("System.Int32");
            gridData.Columns.Add(decCol2);
            DataColumn perCol2 = new DataColumn("ValueToIgnore2");
            perCol2.DataType = System.Type.GetType("System.Int32");
            gridData.Columns.Add(perCol2);
            DataColumn decCol3 = new DataColumn("ValueToSum3");
            decCol3.DataType = System.Type.GetType("System.Int32");
            gridData.Columns.Add(decCol3);
            DataColumn perCol3 = new DataColumn("ValueToIgnore3");
            perCol3.DataType = System.Type.GetType("System.Int32");
            gridData.Columns.Add(perCol3);
  
  
            for (int j = 1; j < 5; j++)
            {
                for (int i = 1; i < 5; i++)
                {
                    DataRow dataRow = contributionData.Tables[0].NewRow();
  
                    dataRow["GroupValue1"] = "Header 1 as " + j.ToString();
                    dataRow["GroupValue2"] = "Heading 2 as " + i.ToString();
                    dataRow["ValueToSum"] = 1234 * i * j;
                    dataRow["ValueToIgnore"] = 805 * i * j;
                    dataRow["ValueToSum2"] = 42 * i * j;
                    dataRow["ValueToIgnore2"] = 901 * i * j;
                    dataRow["ValueToSum3"] = 651 * i * j;
                    dataRow["ValueToIgnore3"] = 104 * i * j;
  
                    contributionData.Tables[0].Rows.Add(dataRow);
                }
            }
            return contributionData;
        }
        #endregion
  
  
    }
}

0
Vasil
Telerik team
answered on 29 Jul 2011, 09:47 AM
Hi,

You could see these help topics that could help you to place the calculations inside the header:
http://www.telerik.com/help/aspnet-ajax/grid-perform-calculations-in-group-header.html
http://www.telerik.com/help/aspnet-ajax/grid-aligning-items-in-group-header.html

Regards,
Vasil
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
wonderbison
Top achievements
Rank 1
answered on 05 Sep 2011, 03:24 PM
None of these items helped so nothing marked as an answer. Closing thread
Tags
Grid
Asked by
wonderbison
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
wonderbison
Top achievements
Rank 1
Vasil
Telerik team
Share this question
or