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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Is it Possible in Summary of gridgroupingcontrol?

Thread ID:

Created:

Updated:

Platform:

Replies:

142293 Jan 25,2019 11:06 AM UTC Mar 12,2019 12:18 PM UTC WinForms 3
loading
Tags: SfDataGrid
Sanjay Kushwaha
Asked On January 25, 2019 11:06 AM UTC

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




Arulraj A [Syncfusion]
Replied On 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 


Sarah
Replied On 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

Jagadeesan Pichaimuthu [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon