Summaries based on other column

Example:
We have two columns Currency and Value.
EUR 1200
EUR 1000
CHF 200
I want add two rows on summary:
Sum EUR 2200
Sum CHF 200
Normal double sum but calculate rows with value in other column.

Any ideas ?
Grouping on Currency is not accepted by users.

4 Replies

KA Krzysztof Adamowicz November 15, 2017 11:42 PM UTC

I did it using new class base on SummaryBase.
I was inspired by example on forum Weightedsummaries
Column descriptor is combination column name, column with currency, summarized currency

Maybe somebody knows better solution



MG Mohanraj Gunasekaran Syncfusion Team November 16, 2017 10:36 AM UTC

Hi Krzysztof, 

By default, GridGroupingControl does not have the direct support to add summaries based on the other columns. But you can achieve your scenario by using SummaryType.Custom summary preoprty and QueryCustomSummary event. In attached sample, we have used two separate methods (CreateEurSummaryMethod and CreateChrSummaryMethod) in SummaryBase class which is the recommended way to achieve your scenario. 

Code example 
this.gridGroupingControl1.QueryCustomSummary += new GridQueryCustomSummaryEventHandler(gridGroupingControl1_QueryCustomSummary); 
 
GridSummaryColumnDescriptor sd0 = new GridSummaryColumnDescriptor(); 
sd0.Name = "EURTotal"; 
sd0.DataMember = "Amount"; 
sd0.DisplayColumn = "Amount"; 
sd0.Format = "EUR:{Total}"; 
sd0.SummaryType = SummaryType.Custom; 
this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(new GridSummaryRowDescriptor("Row 0", "Total", sd0)); 
             
 
GridSummaryColumnDescriptor sd1 = new GridSummaryColumnDescriptor(); 
sd1.Name = "CHRTotal"; 
sd1.DataMember = "Amount"; 
sd1.DisplayColumn = "Amount"; 
sd1.Format = "CHR:{Total}"; 
sd1.SummaryType = SummaryType.Custom; 
this.gridGroupingControl1.TableDescriptor.SummaryRows.Add(new GridSummaryRowDescriptor("Row 1", "Total", sd1)); 
 
private void gridGroupingControl1_QueryCustomSummary(object sender, GridQueryCustomSummaryEventArgs e) 
{ 
    switch (e.SummaryColumn.Name) 
    { 
        case "EURTotal": 
            { 
                e.SummaryDescriptor.CreateSummaryMethod = new CreateSummaryDelegate(TotalSummary.CreateEurSummaryMethod); 
                break; 
            } 
        case "CHRTotal": 
            { 
                e.SummaryDescriptor.CreateSummaryMethod = new CreateSummaryDelegate(TotalSummary.CreateChrSummaryMethod); 
                break; 
            } 
    } 
} 
 
Screenshot 
 
 
Sample link: GridGroupingControl 
 
Please refer the below UG and KB links, 
 

Please let us know if you have any other concerns. 

Regards, 
Mohanraj G 



KA Krzysztof Adamowicz November 18, 2017 11:47 PM UTC

Looks fine


MG Mohanraj Gunasekaran Syncfusion Team November 20, 2017 03:56 AM UTC

Hi Krzysztof, 
 
Thanks for your update. 
 
We are glad to know that your reported problem has resolved. 
 
Please let us know if you have any concerns. 
 
Regards, 
Mohanraj G 


Loader.
Up arrow icon