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 in function of field value

Thread ID:

Created:

Updated:

Platform:

Replies:

120927 Oct 28,2015 12:57 PM UTC Nov 1,2017 12:29 PM UTC ASP.NET Web Forms 7
loading
Tags: Grid
Manolo
Asked On October 28, 2015 12:57 PM UTC

Hi,

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

Gowthami V [Syncfusion]
Replied On October 29, 2015 10:40 AM UTC

Hi Manolo,

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:Grid ID="OrdersGrid" runat="server" AllowPaging="True" ShowSummary="true" >
. . . .
. . . .
<SummaryRows>

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


        }
//Getting close status data for summarize

function getCloseData(summaryvalue)

        {

            for (var i = 0; i < summaryvalue.length; i++) {

                if (summaryvalue[i].Status == "close")

                    data1[i] = summaryvalue[i];

            }

            return data1;

        }

        </script>


</asp:Content>


Regards,

Gowthami V.

Manolo
Replied On October 29, 2015 12:02 PM UTC

Hi,

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?

Gowthami V [Syncfusion]
Replied On October 30, 2015 12:52 PM UTC

Hi Manolo,

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.

Manolo
Replied On October 30, 2015 01:00 PM UTC

Thank you

Gowthami V [Syncfusion]
Replied On November 2, 2015 10:38 AM UTC

Hi Manolo,
 
Please follw up the incident which is created under your account for further assistance.
 
Thanks & Regards,
Gowthami V.

Pierre Custeau
Replied On November 1, 2017 02:06 AM UTC

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


Mani Sankar Durai [Syncfusion]
Replied On November 1, 2017 12:29 PM UTC

Hi Pierre, 

We have analyzed your query and we found that you want to export the grid with custom summary value in grid. But due to exception thrown you have removed the customer summary row while exporting. We can export the grid with custom summary using the below code example 

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; 
        } 
  
We have also prepared a sample that can be downloaded from the below link 
 
Please let us know if you need further assistance. 
 
Regards, 
Manisankar Durai. 


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

;