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

Group header aggregates and footers aggregates

9 Answers 291 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 28 Oct 2008, 03:50 PM
I have a RadGrid where I am grouping by expression and I'm aggregating some values in the group header.  The aggregates in the group header work fine and total all the values in the group as expected until I set the Aggregate property of the GridBoundColumn field to Sum of the field I'm trying to aggregate in the group header.  instead of having a total of the group in the group header for that field, just the last value of the group is being placed in the group header.  I need to have group totals in the group header and then overall totals in the grid footer.  Is there a way to do this? 

9 Answers, 1 is accepted

Sort by
0
Phil
Top achievements
Rank 1
answered on 28 Oct 2008, 04:25 PM
Nevermind.  I figured it out.  I just had to use aliases that were different from the fields in my GridBoundColumn in my GridGroupByExpression and the GridGroupByFields.
0
Le
Top achievements
Rank 1
answered on 13 May 2009, 07:54 AM
Hello,
I got the issue like that.How to set the value of Group Header into the value of Group Footer when I add groupby expression.
I use GridBoundColumn to show the value of Group Footer, but the result is wrong when I add two or three 'group by' expression.
I need the value of grid footer is the same with Group Header.
Plz help me, Thanks!!!

Best regards,
Le

0
Le
Top achievements
Rank 1
answered on 18 May 2009, 04:20 AM
Plz, help me!!!
Best regards,
Le
0
Rosen
Telerik team
answered on 19 May 2009, 10:15 AM
Hello Le,

Can you please download latest internal build and see if it helps?

Sincerely yours,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Le
Top achievements
Rank 1
answered on 20 May 2009, 01:29 AM
Hi,
I get the lasted version 2009.1 402 and It's the snippet code to show Group Footer in RadGrid

        

GridBoundColumn colCount = (GridBoundColumn)RadGrid1.MasterTableView.Columns.FindByDataField("COLUMNNAME");

 

 

colCount.Aggregate = GridAggregateFunction.Count;

 

 

colCount.FooterAggregateFormatString =

"Count " + r.CAPTION + ":{0}";

 

But the value of Group Header and Group Footer are not the same (RadGrid added two or more groupby expression)

Any help!!

 

Thanks,
Le

 

0
Le
Top achievements
Rank 1
answered on 25 May 2009, 04:34 AM
Plz help me,
I got the lastest internal Build 2009-1-519, and I test this version with small project which run right. In my scenario,the value of Group Footer went wrong, when i added 2 or 3 groupby expression.I don't know why, plz help me check!!!
And this is my snippet code:
private void CreateColumnAndBindData(DataTable dt, DataTable dtColumn) 
    { 
        #region Create Columns 
        foreach (DataColumn col in dt.Columns) 
        { 
            DataRow[]  dr = dtColumn.Select("COLUMNNAME = '" + col.ColumnName + "'"); 
            if (dr.Length > 0) 
            { 
                ds.TBL_COLUMNRow r = dr[0] as ds.TBL_COLUMNRow; 
                 
                switch (r.DATATYPE) 
                { 
                    case "NUMBER"
                         
                        GridBoundColumn grdColumn = new GridBoundColumn();                         
                        grdColumn.DataField = r.COLUMNNAME; 
                        grdColumn.HeaderText = r.CAPTION; 
                        grdColumn.UniqueName = r.COLUMNNAME; 
                        grdColumn.SortExpression = r.COLUMNNAME; 
                        grdColumn.DataType = Type.GetType("System.Decimal"); 
                        grdReport.MasterTableView.Columns.Add(grdColumn); 
                        break
                    case "NVARCHAR2"
                        GridBoundColumn grdColumn1 = new GridBoundColumn(); 
                        grdColumn1.DataField = r.COLUMNNAME; 
                        grdColumn1.HeaderText = r.CAPTION; 
                        grdColumn1.UniqueName = r.COLUMNNAME; 
                        grdColumn1.SortExpression = r.COLUMNNAME; 
                        grdColumn1.DataType = Type.GetType("System.String"); 
                        grdReport.MasterTableView.Columns.Add(grdColumn1); 
                        break
                    case "VARCHAR2"
                        GridBoundColumn grdColumn2 = new GridBoundColumn(); 
                        grdColumn2.DataField = r.COLUMNNAME; 
                        grdColumn2.HeaderText = r.CAPTION; 
                        grdColumn2.UniqueName = r.COLUMNNAME; 
                        grdColumn2.SortExpression = r.COLUMNNAME; 
                        grdColumn2.DataType = Type.GetType("System.String"); 
                        grdReport.MasterTableView.Columns.Add(grdColumn2); 
                        break
                    case "DATE"
                        GridBoundColumn grdDateColumn = new GridBoundColumn(); 
                        grdDateColumn.DataField = r.COLUMNNAME; 
                        grdDateColumn.HeaderText = r.CAPTION; 
                        grdDateColumn.UniqueName = r.COLUMNNAME; 
                        grdDateColumn.SortExpression = r.COLUMNNAME;                        
                        grdDateColumn.DataFormatString = "{0:M/d/yyyy}"
                        grdDateColumn.DataType = Type.GetType("System.DateTime");                         
                        grdReport.MasterTableView.Columns.Add(grdDateColumn); 
                        break
                    case "TIMESTAMP(6) WITH LOCAL TIME ZONE"
                        GridBoundColumn grdDateColumn1 = new GridBoundColumn(); 
                        grdDateColumn1.DataField = r.COLUMNNAME; 
                        grdDateColumn1.HeaderText = r.CAPTION; 
                        grdDateColumn1.UniqueName = r.COLUMNNAME; 
                        grdDateColumn1.SortExpression = r.COLUMNNAME; 
                        grdDateColumn1.DataFormatString = "{0:M/d/yyyy}"
                        grdDateColumn1.DataType = Type.GetType("System.DateTime"); 
                        grdReport.MasterTableView.Columns.Add(grdDateColumn1); 
                        break
                    default
                        GridBoundColumn grdColumn3 = new GridBoundColumn(); 
                        grdColumn3.DataField = r.COLUMNNAME; 
                        grdColumn3.HeaderText = r.CAPTION; 
                        grdColumn3.UniqueName = r.COLUMNNAME; 
                        grdColumn3.SortExpression = r.COLUMNNAME; 
                        grdColumn3.DataType = Type.GetType("System.Decimal"); 
                        grdReport.MasterTableView.Columns.Add(grdColumn3); 
                        break
                } 
                 
            } 
        } 
        #endregion 
        #region Create Expression 
 
        int iIndex = 0; 
        try 
        { 
            foreach (dsReportInfor.TBL_COLUMNTOGROUPBYRow rGroupBy in ReportInfor.TBL_COLUMNTOGROUPBY) 
            { 
                DataRow[] dr = dtColumn.Select("COLUMNID = '" + rGroupBy.COLUMNID + "'"); 
                if (dr.Length > 0) 
                { 
                    GridGroupByExpression ex = new GridGroupByExpression(); 
                    ds.TBL_COLUMNRow r = dr[0] as ds.TBL_COLUMNRow; 
                    GridGroupByField f = new GridGroupByField(); 
                    f.FieldName = r.COLUMNNAME; 
                    f.HeaderText = r.CAPTION; 
                    ex.GroupByFields.Add(f); 
                    ex.SelectFields.Add(f); 
                    grdReport.MasterTableView.GroupByExpressions.Add(ex); 
 
                    iIndex++; 
                } 
            } 
         
 
        } 
        catch (Exception ex) 
        { 
            ShowValidate(string.Format("<strong>Cannot add group by expression: {0}</strong><br>", ex.Message)); 
        } 
        if (iIndex > 0) 
        { 
            grdReport.ShowGroupPanel = true
            //grdReport.MasterTableView.AllowPaging = false; 
        } 
 
        int n = 0; 
        foreach (dsReportInfor.TBL_COLUMNTOTOTALRow rColumn2Total in ReportInfor.TBL_COLUMNTOTOTAL) 
        { 
            DataRow[] dr = dtColumn.Select("COLUMNID = '" + rColumn2Total.COLUMNID + "'"); 
            if (dr.Length > 0 && ReportInfor.TBL_COLUMNTOGROUPBY.Select("COLUMNID = '" + rColumn2Total.COLUMNID + "'").Length == 0) 
            { 
                ds.TBL_COLUMNRow r = dr[0] as ds.TBL_COLUMNRow; 
                for (int i = 0; i < iIndex; i++) 
                { 
                    if (Convert.ToBoolean(rColumn2Total.GETMIN)) 
                    { 
                        GridGroupByField f = new GridGroupByField(); 
                        f.HeaderText = r.CAPTION; 
                        f.FieldName = r.COLUMNNAME; 
                        f.FieldAlias = "F" + n++; 
                        f.HeaderText = "Min " + r.CAPTION; 
                        f.Aggregate = GridAggregateFunction.Min; 
                        grdReport.MasterTableView.GroupByExpressions[i].SelectFields.Add(f); 
                         
                        //Customize FooterGroup 
                        GridBoundColumn colMin = (GridBoundColumn)grdReport.MasterTableView.Columns.FindByUniqueName(r.COLUMNNAME); 
                        colMin.Aggregate = GridAggregateFunction.Min; 
                        //colMin.FooterText = "Min " + r.CAPTION + " : "; 
                        if (r.DATATYPE.Equals("DATE") || r.DATATYPE.Equals("TIMESTAMP(6) WITH LOCAL TIME ZONE")) 
                        { 
                            colMin.FooterAggregateFormatString = "Min " + r.CAPTION + ":{0:M/d/yyyy}"
                            //f.FormatString = "{0:M/d/yyyy}"; 
                        } 
                        else 
                            colMin.FooterAggregateFormatString = "Min " + r.CAPTION + ":{0:c}"
 
                    } 
                    if (Convert.ToBoolean(rColumn2Total.GETMAX)) 
                    { 
                        GridGroupByField f = new GridGroupByField(); 
                        f.HeaderText = r.CAPTION; 
                        f.FieldName = r.COLUMNNAME; 
                        f.FieldAlias = "F" + n++; 
                        f.HeaderText = "Max " + r.CAPTION; 
                        f.Aggregate = GridAggregateFunction.Max; 
                        grdReport.MasterTableView.GroupByExpressions[i].SelectFields.Add(f); 
 
                        //Customize FooterGroup 
                        GridBoundColumn colMax = (GridBoundColumn)grdReport.MasterTableView.Columns.FindByUniqueName(r.COLUMNNAME); 
                        colMax.Aggregate = GridAggregateFunction.Max; 
                        //colMax.FooterText = "Max " + r.CAPTION + " : "; 
 
                        if (r.DATATYPE.Equals("DATE") || r.DATATYPE.Equals("TIMESTAMP(6) WITH LOCAL TIME ZONE")) 
                        { 
                            colMax.FooterAggregateFormatString = "Max " + r.CAPTION + ":{0:M/d/yyyy}"
                            //f.FormatString = "{0:M/d/yyyy}"; 
                        } 
                        else 
                            colMax.FooterAggregateFormatString = "Max " + r.CAPTION + ":{0}"
 
                    } 
                    if (Convert.ToBoolean(rColumn2Total.GETAVG) && !r.DATATYPE.Equals("DATE") && !r.DATATYPE.Equals("TIMESTAMP(6) WITH LOCAL TIME ZONE")) 
                    { 
                        GridGroupByField f = new GridGroupByField(); 
                        f.HeaderText = r.CAPTION; 
                        f.FieldName = r.COLUMNNAME; 
                        f.FieldAlias = "F" + n++; 
                        //f.HeaderText = "Avg " + r.CAPTION; 
                        f.Aggregate = GridAggregateFunction.Avg; 
                        f.FormatString = "Avg:{0:0.00}"
                        grdReport.MasterTableView.GroupByExpressions[i].SelectFields.Add(f); 
                        //expression.SelectFields.Add(f); 
 
                        //Customize FooterGroup 
                        GridBoundColumn colAvg = (GridBoundColumn)grdReport.MasterTableView.Columns.FindByUniqueName(r.COLUMNNAME); 
                        colAvg.Aggregate = GridAggregateFunction.Avg; 
                        colAvg.FooterAggregateFormatString = "Avg " + r.CAPTION + ":{0:0.00}"
 
                    } 
                    if (Convert.ToBoolean(rColumn2Total.GETSUM) && !r.DATATYPE.Equals("DATE") && !r.DATATYPE.Equals("TIMESTAMP(6) WITH LOCAL TIME ZONE")) 
                    { 
                        GridGroupByField f = new GridGroupByField(); 
                        f.HeaderText = r.CAPTION; 
                        f.FieldName = r.COLUMNNAME; 
                        f.FieldAlias = "F" + n++; 
                        f.HeaderText = "Sum " + r.CAPTION; 
                        //f.FormatString = "Sum:{0:C2}"; 
                        f.Aggregate = GridAggregateFunction.Sum; 
                        grdReport.MasterTableView.GroupByExpressions[i].SelectFields.Add(f); 
 
                        //Customize FooterGroup 
                        GridBoundColumn colSum = (GridBoundColumn)grdReport.MasterTableView.Columns.FindByUniqueName(r.COLUMNNAME); 
 
                        //colSum.FooterAggregateFormatString = "Sum:{0}"; 
                        //colSum.FooterText = "Sum " + r.CAPTION + " : "; 
 
                        if (string.IsNullOrEmpty(colSum.FooterAggregateFormatString)) 
                        { 
                            colSum.FooterAggregateFormatString = "Sum " + r.CAPTION + ":{0}"
                            colSum.Aggregate = GridAggregateFunction.Sum; 
                        } 
                         
 
                    } 
                    if (Convert.ToBoolean(rColumn2Total.GETCOUNT)) 
                    { 
                        GridGroupByField f = new GridGroupByField(); 
                        f.HeaderText = r.CAPTION; 
                        f.FieldName = r.COLUMNNAME; 
                        f.FieldAlias = "F" + n++; 
                        f.HeaderText = "Count " + r.CAPTION; 
                        f.Aggregate = GridAggregateFunction.Count; 
                        grdReport.MasterTableView.GroupByExpressions[i].SelectFields.Add(f); 
 
                        //Customize FooterGroup 
                        GridBoundColumn colCount = (GridBoundColumn)grdReport.MasterTableView.Columns.FindByUniqueName(r.COLUMNNAME); 
                        //colCount.FooterText = "Count " + r.CAPTION + " : "; 
                        colCount.Aggregate = GridAggregateFunction.Count; 
                        colCount.FooterAggregateFormatString = "Count " + r.CAPTION + ":{0}"
                         
                    } 
                }//end for 
            }//end if 
            n++; 
        } 
      
        #endregion 
        #region Create formular columns 
        foreach (dsReportInfor.TBL_FORMULACOLUMNRow rFomularColumn in ReportInfor.TBL_FORMULACOLUMN) 
        { 
            if (rFomularColumn.FORMASTER.Equals(0)) 
            { 
                GridBoundColumn grdColumn = new GridBoundColumn(); 
                grdColumn.DataField = rFomularColumn.CAPTION; 
                grdColumn.HeaderText = rFomularColumn.CAPTION; 
                grdReport.MasterTableView.Columns.Add(grdColumn); 
            } 
        } 
        #endregion 
 
        grdReport.DataSource = dt; 
    } 
Plz help me review it!!!
Best regards,
Le
0
Rosen
Telerik team
answered on 25 May 2009, 05:53 AM
Hi Le,

Indeed there is an issue with group footer aggregate which our developers are currently investigating.

Please excuse us inconvenience.

Sincerely yours,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Le
Top achievements
Rank 1
answered on 25 May 2009, 06:18 AM
Hello,
Plz tell me immediately when you fix this issue.
Thanks & best regards,
Le


0
Rosen
Telerik team
answered on 28 May 2009, 06:04 AM
Hello,

I'm happy to inform you that our developers has managed to address the grouping footers calculation issue. Please download Q1 2009 SP2 release and see if it helps.

Regards,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Phil
Top achievements
Rank 1
Answers by
Phil
Top achievements
Rank 1
Le
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or