<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>
|
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;
} |