We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Is it Possible in Summary of gridgroupingcontrol?

Dear Team,

Is it possible to calculate (Sum(ColA)/Sum(ColB)) in summary of gridgroupingcontrol.

Like in given example 
Correct calculation-> (Sum(ColA)/Sum(ColB)): 30940/265 = 116.75

Incorrect Calculation-> Avg(ColC)= 116.57




3 Replies

AA Arulraj A Syncfusion Team January 28, 2019 09:55 AM UTC

 
Thanks for using Syncfusion product. 
 
To add the summary based on the other column, you could add the GridSummaryRowDescriptor using SummaryRows and get that summary row values in QueryCellStyleInfo event to achieve your requirement. Please refer following code example. 
 
C# 
GridSummaryColumnDescriptor scd1 = new GridSummaryColumnDescriptor("SummaryColumn1", Syncfusion.Grouping.SummaryType.Int32Aggregate, "ColumnA", "{Sum}"); 
GridSummaryColumnDescriptor scd2 = new GridSummaryColumnDescriptor("SummaryColumn2", Syncfusion.Grouping.SummaryType.Int32Aggregate, "ColumnB", "{Sum}"); 
GridSummaryColumnDescriptor scd3 = new GridSummaryColumnDescriptor("SummaryColumn3", Syncfusion.Grouping.SummaryType.Custom, "ColumnC", ""); 
GridSummaryRowDescriptor srd = new GridSummaryRowDescriptor(); 
srd.SummaryColumns.AddRange(new GridSummaryColumnDescriptor[] { scd1, scd2, scd3 }); 
this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(srd); 
 
this.gridGroupingControl1.QueryCellStyleInfo += GridGroupingControl1_QueryCellStyleInfo; 
private void GridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) 
{ 
    if (e.TableCellIdentity == null) 
        return; 
 
    if (e.TableCellIdentity.TableCellType == GridTableCellType.SummaryFieldCell && e.TableCellIdentity.SummaryColumn.Name == "SummaryColumn3") 
    { 
        GridSummaryRow row = e.TableCellIdentity.DisplayElement as GridSummaryRow; 
        if (row != null) 
        { 
            int col1 = 0; 
            int col2 = 0; 
            foreach (var scd in row.SummaryRowDescriptor.SummaryColumns) 
            { 
                if (scd.Name == "SummaryColumn1") 
                { 
                    var text1 = scd.GetDisplayText(row.ParentGroup); 
                    int.TryParse(text1, out col1); 
                } 
                else if (scd.Name == "SummaryColumn2") 
                { 
                    var text2 = scd.GetDisplayText(row.ParentGroup); 
                    int.TryParse(text2, out col2); 
                } 
            } 
            if (col2 > 0) 
                e.Style.CellValue = (double)col1 / (double)col2; 
        } 
    } 
} 
 
 
Please refer the below UG and KB link to know more about the custom summary, 
 
Regards, 
Arulraj A 



SA Sarah March 10, 2019 05:04 PM UTC

Hi Arulraj A,

I am trying to do the same thing with the sfDataGrid, can you please provide an example in vb.net for the sfDataGrid?

Thanks


JP Jagadeesan Pichaimuthu Syncfusion Team March 12, 2019 12:18 PM UTC

Hi Sarah, 
  
Thanks for your update. 
  
You can calculate summary value for one column based on the summary values of other columns by changing the display text in the SfDataGrid.DrawCell event with required value. Please refer the following KB to calculate the summary value based on other columns summary values. 
  
  
Please let us know if you require any further assistance in this. 
  
Regards, 
Jagadeesan 


Loader.
Live Chat Icon For mobile
Up arrow icon