Calculate two summaries?

Hello everybody,
I have a question?
Is it possible that I can calculate two summaries.
My programming experience is not that good at the moment, but I'm working on it.
Look at the picture, the summary of the columns (red and green) but now I need the final price (the green price minus the red price) is then the final price


Does anyone have any idea how I can do this?
best regards

1 Reply 1 reply marked as answer

DM Dhanasekar Mohanraj Syncfusion Team October 7, 2020 02:55 PM UTC

Hi Patrick,

 
Thank you for using Syncfusion Controls.

 
We have checked your requirement you can achieve this by overriding the OnRender method in GridTableSummaryCellRenderer like below,

 
this.sfDataGrid1.CellRenderers.Remove("TableSummary"); 
this.sfDataGrid1.CellRenderers.Add("TableSummary", new CustomGridTableSummaryRenderer(this.sfDataGrid1));

public
class CustomGridTableSummaryRenderer : GridTableSummaryCellRenderer 
{ 
    public CustomGridTableSummaryRenderer(SfDataGrid dataGrid) 
    { 
        IsEditable = true; 
        DataGrid = dataGrid; 
    } 
    protected SfDataGrid DataGrid { get; set; } 
 
    protected override void OnRender(Graphics paint, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex) 
    { 
        if(((DataGrid.View.Records.Count+ DataGrid.TableSummaryRows.Count)) == rowColumnIndex.RowIndex) 
        { 
            var summary1 = (SummaryCreator.GetSummaryDisplayText(DataGrid.View.Records.TableSummaries[0], "Quantity" , DataGrid.View)); 
            var summary2 = SummaryCreator.GetSummaryDisplayText(DataGrid.View.Records.TableSummaries[0], "UnitPrice", DataGrid.View);                                                                                                                                            
            summary1 = summary1.Replace("$", ""); 
            summary2 = summary2.Replace("$", ""); 
            if (string.IsNullOrEmpty(cellValue)) 
                return; 
            NumberFormatInfo format = new NumberFormatInfo(); 
            cellValue = (Convert.ToDouble((Convert.ToDouble(summary1) - Convert.ToDouble(summary2)))).ToString(); 
            StringFormat stringFormat = new StringFormat(); 
            stringFormat.LineAlignment = StringAlignment.Center; 
            stringFormat.Alignment = StringAlignment.Center; 
            paint.DrawString(cellValue, style.Font.GetFont(), Brushes.Black, cellRect, stringFormat); 
        } 
        else 
        base.OnRender(paint, cellRect, cellValue, style, column, rowColumnIndex); 
    } 
} 

We have prepared sample for the same,

 


 
Please let us know, if you need any further assistance.

 
Regards,
Dhanasekar Mohanraj. 


Marked as answer
Loader.
Up arrow icon