Custom Summary with DataTable as ItemsSource
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.
SIGN IN To post a reply.
5 Replies
SV
Srinivasan Vasu
Syncfusion Team
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.
Sample Link: http://www.syncfusion.com/downloads/support/directtrac/general/ze/DataTable-1614115018.zip
Regards,
Srinivasan
AS
Amit Saraf
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
JG
Jai Ganesh S
Syncfusion Team
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
AS
Amit Saraf
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");
|
JG
Jai Ganesh S
Syncfusion Team
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
SIGN IN To post a reply.
- 5 Replies
- 3 Participants
-
AS Amit Saraf
- Feb 15, 2017 11:27 AM UTC
- Feb 22, 2017 03:40 AM UTC