- Home
- Forum
- ASP.NET Web Forms
- Custom Summary in function of field value
Custom Summary in function of field value
I want show a summary in function of a field status value. For example in the next image:
The summary TotalOpen must summarize the values when status is open and TotalClose must summarize the values when status is close.
I attach this example project
Thanks
Attachment: stackedHeader_92da7bef.zip
Thanks for using Syncfusion products.
We have modified your sample with custom summary function for calculating sum and average based on open and close status and the same can be downloaded from the following link,
http://www.syncfusion.com/downloads/support/forum/120927/STACKE~2357236878.ZIP
In the above sample, we have set SummaryType as “CustomSummary” and summarized the open and close status data alone for TotalOpen and TotalClose summary field respectively.
Refer to the below code example,
|
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<div> <ej:SummaryRow Title="Total Open"> <SummaryColumn> <ej:SummaryColumn SummaryType="Custom" CustomSummaryValue="sumOpen" DisplayColumn="Freight" Format="{0:C2}" /> . . . . </ej:SummaryRow> </SummaryRows>
<SummaryRows> <ej:SummaryRow Title="Total Close"> <SummaryColumn> <ej:SummaryColumn SummaryType="Custom" CustomSummaryValue="sumClose" Format="{0:C}" DisplayColumn="Freight" DataMember="Freight" /> . . . . </SummaryColumn> </ej:SummaryRow> </SummaryRows> <script type="text/javascript"> var data = [],data1=[]; //Custom summary function sumOpen function sumOpen(summaryCol, summaryValue) { var data = getOpenData(summaryValue); //sum the data return ej.sum(data, summaryCol.displayColumn); } //Getting open status data for summarize function getOpenData(summaryvalue) { var j = 0; for (var i = 0; i < summaryvalue.length; i++) { if (summaryvalue[i].Status == "open") { data[j] = summaryvalue[i]; j++; } } return data; } //Custom summary function sumClose function sumClose(summaryCol, summaryValue) { var data = getCloseData(summaryValue); return ej.sum(data, summaryCol.displayColumn);
function getCloseData(summaryvalue) { for (var i = 0; i < summaryvalue.length; i++) { if (summaryvalue[i].Status == "close") data1[i] = summaryvalue[i]; } return data1; } </script>
|
Regards,
Gowthami V.
Thank you very much! It works perfectly.
But... if I want export to excel this grid, the custom summaries exports is not calculate and the cell value is the name function.
Can I export to excel with the result value?
We have created a new support incident for the issue “Need to provide support for calling QueryCellInfo event for Custom Summary cell” under your account to track the status of this issue. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents
Regards,
Gowthami V.
Please follw up the incident which is created under your account for further assistance.
Thanks & Regards,
Gowthami V.
Was this issue ever solved? I'm having to remove custom summary columns / rows in my server code otherwise exporting to excel (when the dataset is passed from client) will fail with an error. Here is the mod I have applied on the server as a temporary fix (ASP.Net core 1.1):
private GridProperties ConvertGridObject(string gridProperty)
{
GridProperties gridProp = new GridProperties();
gridProp = (GridProperties)JsonConvert.DeserializeObject(gridProperty, typeof(GridProperties));
//bug with custom summary types we need to pull them out
foreach (var summaryRow in gridProp.SummaryRows)
{
summaryRow.SummaryColumns.RemoveAll(s => s.SummaryType == Syncfusion.JavaScript.SummaryType.Custom);
}
return gridProp;
}
Shouldn't calculated summary values be simply passed as is to the server for inclusion in the Excel document ?
Thanks
|
public ActionResult ExportToExcel(string GridModel)
{
ExcelExport exp = new ExcelExport();
var DataSource = orders;
GridProperties gridProp = ConvertGridObject(GridModel);
GridExcelExport excelExp = new GridExcelExport();
excelExp.QueryCustomSummaryInfo = QueryCellInfo; //with the server side event QueryCustomeSummaryInfo
excelExp.FileName = "Export.xlsx"; excelExp.Excelversion = ExcelVersion.Excel2010;
excelExp.Theme = "flat-saffron";
return exp.Export(gridProp, DataSource, excelExp);
}
public object QueryCellInfo(IQueryable Items, SummaryColumn col)
{
IQueryable data = GetData().Where(c => c.EmployeeID == 2).AsQueryable();
var elementType = data.ElementType;
//Calculating average of Freight field and convert it to decimal
var items = Convert.ToDecimal(data.Average("Freight", elementType));
//Calculating sum of Freight field and convert it to decimal
var items1 = Convert.ToDecimal(data.Sum("Freight", elementType));
return items1;
} |
- 7 Replies
- 4 Participants
-
MA Manolo
- Oct 28, 2015 12:57 PM UTC
- Nov 1, 2017 12:29 PM UTC