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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Custom Summary with DataTable as ItemsSource

Thread ID:

Created:

Updated:

Platform:

Replies:

128911 Feb 15,2017 11:27 AM UTC Feb 22,2017 03:40 AM UTC WPF 5
loading
Tags: SfDataGrid
Amit Saraf
Asked On February 15, 2017 11:27 AM UTC

I've a DataTable with following Columns (example)

No.   Prod  Qty  Rate  Amt
1.     P1       10   100   1000
2.    P1        5      102     510
3.    P1         9     100     900

I want to Show (amt / Qty) i.e average rate in summary column (Group & Table Summary Row)

How can I achieve this.

Srinivasan Vasu [Syncfusion]
Replied On February 16, 2017 07:28 AM UTC

Hi Amit, 
 
Thanks for contacting Syncfusion support. 
 
We have analyzed your query and we have provided support for Table and Group Summary for columns in SfDataGrid.  You can specify the different summary aggregate types by using GridSummaryColumn.SummaryType property and use the built-in function in GridSummaryColumn.Format. 
 
Please refer the below UG Link to know about summaries. 
 
 
 
 
 
Regards, 
Srinivasan 
 


Amit Saraf
Replied On February 16, 2017 12:48 PM UTC

Thanks for your reply

Here is what I want

No.   Prod  Qty  Rate  Amt
1.     P1       10   100   1000
2.    P1        5      102     510
3.    P1         9     100     900
=====================
                  24      ???         2410

??? => Amt / Qty  =>  2410 / 24 = 100.42

I want 100.42 in rate column in summary row

I want to calculate Amount/Quantity and place it in Rate Column i.e. Average Rate 
(COUNT, SUM & Average is already available in SfDataGrid for Same Column) but I want the result from 2 different columns and place it in 3rd column

Thanks in advance

Jai Ganesh S [Syncfusion]
Replied On February 19, 2017 11:08 AM UTC

Hi Amit,  
 
You can achieve your requirement by customizing the GridTableSummaryCellRenderer like below, 
 
this.syncgrid.CellRenderers.Remove("TableSummary"); 
this.syncgrid.CellRenderers.Add("TableSummary", new GridTableSummaryCellRendererExt()); 
 
public class GridTableSummaryCellRendererExt : GridTableSummaryCellRenderer 
    { 
        public override void OnInitializeEditElement(DataColumnBase dataColumn, GridTableSummaryCell uiElement, object dataContext) 
        { 
            base.OnInitializeEditElement(dataColumn, uiElement, dataContext); 
            GridColumn column = dataColumn.GridColumn; 
            if (dataContext is SummaryRecordEntry) 
            { 
                var record = dataContext as SummaryRecordEntry; 
 
                if (column.MappingName == "Rate") 
                { 
                    double quality = double.Parse(record.SummaryValues[0].AggregateValues["Sum"].ToString()); 
                    double amount = double.Parse(record.SummaryValues[2].AggregateValues["Sum"].ToString()); 
                    var rate = amount / quality; 
                    uiElement.Content = rate; 
 
                } 
            } 
        } 
 
        public override void OnUpdateEditBinding(DataColumnBase dataColumn, GridTableSummaryCell element, object dataContext) 
        { 
            base.OnUpdateEditBinding(dataColumn, element, dataContext); 
 
            GridColumn column = dataColumn.GridColumn; 
            if (dataContext is SummaryRecordEntry) 
            { 
                var record = dataContext as SummaryRecordEntry; 
 
                if(column.MappingName=="Rate") 
                { 
                    double quality=double.Parse(record.SummaryValues[0].AggregateValues["Sum"].ToString()); 
                    double amount = double.Parse(record.SummaryValues[2].AggregateValues["Sum"].ToString()); 
                    var  rate = amount / quality; 
                    element.Content = rate; 
                } 
            } 
        } 
    } 
 
 
 
Regards, 
Jai Ganesh S 


Amit Saraf
Replied On February 21, 2017 06:43 AM UTC

Thanks for your reply

Table Summary worked perfectly as I wanted

For Group Summary I did this (it is working, but please let me know if I'm wrong)


                    LV.CellRenderers.Remove("GroupSummary");
                    LV.CellRenderers.Add("GroupSummary", new GridGroupSummaryCellRendererExt());

    class GridGroupSummaryCellRendererExt : sync.Grid.Cells.GridSummaryCellRenderer
    {
        public override void OnInitializeEditElement(sync.Grid.DataColumnBase dataColumn, sync.Grid.GridGroupSummaryCell uiElement, object dataContext)
        {
            base.OnInitializeEditElement(dataColumn, uiElement, dataContext);
            sync.Grid.GridColumn column = dataColumn.GridColumn;

            if (dataContext is syncdata.SummaryRecordEntry)
            {
                var record = dataContext as syncdata.SummaryRecordEntry;

                if (column.MappingName == "Rate")
                {
                    decimal quality = decimal.Parse(record.SummaryValues[1].AggregateValues["Sum"].ToString());
                    decimal amount = decimal.Parse(record.SummaryValues[3].AggregateValues["Sum"].ToString());
                    var rate = amount / quality;
                    uiElement.Content = rate.ToString("N2");
                }
            }

        }

        public override void OnUpdateEditBinding(sync.Grid.DataColumnBase dataColumn, sync.Grid.GridGroupSummaryCell element, object dataContext)
        {
            base.OnUpdateEditBinding(dataColumn, element, dataContext);
            sync.Grid.GridColumn column = dataColumn.GridColumn;

            if (dataContext is syncdata.SummaryRecordEntry)
            {
                var record = dataContext as syncdata.SummaryRecordEntry;

                if (column.MappingName == "Rate")
                {
                    decimal quality = decimal.Parse(record.SummaryValues[1].AggregateValues["Sum"].ToString());
                    decimal amount = decimal.Parse(record.SummaryValues[3].AggregateValues["Sum"].ToString());
                    var rate = amount / quality;
                    element.Content = rate.ToString("N2");
                }
            }
        }
    }

Jai Ganesh S [Syncfusion]
Replied On February 22, 2017 03:40 AM UTC

Hi Amit, 
Thank you for the update. 
You can use your code to achieve the same in GroupSummary and it will be working fine only. 
Regards, 
Jai Ganesh S 


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.

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

;