Export to excel and pdf don't show correct custom totals

Hello,

I have custom Footer Template fields in the GridAgregateColumns.  When exporting this is what I get:

Custom:0 Custom:0 Sum:40 Sum:-2


It displays correctly on the report:

Total: 50% 40 2 too many


Sample code below where XXXX replaces actual field names:

                                <GridAggregateColumns>

                                    <GridAggregateColumn Field="XXXX" Type="AggregateType.Custom">

                                        <FooterTemplate>

                                                <span>Total:</span>

                                        </FooterTemplate>

                                    </GridAggregateColumn>

                                    <GridAggregateColumn Field="XXXX" Type="AggregateType.Custom">

                                        <FooterTemplate>

                                            @{

                                                <span>@CustomAggregateCalc()%</span>

                                            }

                                        </FooterTemplate>

                                    </GridAggregateColumn>

                                    <GridAggregateColumn Field="XXXX" Type="AggregateType.Sum">

                                        <FooterTemplate>

                                            @{

                                                var aggregate = (context as AggregateTemplateContext);

                                                <span>

                                                    @aggregate.Sum

                                                </span>

                                            }

                                        </FooterTemplate>

                                    </GridAggregateColumn>

                                    <GridAggregateColumn Field="XXXXX" Type="AggregateType.Sum">

                                        <FooterTemplate>

                                            @{

                                                var aggregate = (context as AggregateTemplateContext);

                                                int sum = 0;

                                                int.TryParse(aggregate.Sum, out sum);

                                                var delta = aggregate.Sum + " too many";

                                                if (sum < 0) delta = (sum * -1).ToString() + " too few";

                                                if (sum == 0) delta = "0";

                                                <span>

                                                    @delta

                                                </span>

                                            }

                                        </FooterTemplate>

                                    </GridAggregateColumn>

                                </GridAggregateColumns>


3 Replies

RS Renjith Singh Rajendran Syncfusion Team March 21, 2022 11:45 AM UTC

Hi Jason, 
 
Greetings from Syncfusion support. 
 
Based on this scenario, we suggest you to ensure to handle the aggregates in ExcelAggregateTemplateInfo and PdfAggregateTemplateInfo event handlers of Grid. Please refer and use as like the code below, 
 
 
<GridEvents OnToolbarClick="ToolbarClickHandler" ExcelAggregateTemplateInfo="ExcelAggregateTemplateInfo" PdfAggregateTemplateInfo="PdfAggregateTemplateInfo" TValue="Product"></GridEvents> 
    <GridAggregates> 
        <GridAggregate> 
            <GridAggregateColumns> 
                <GridAggregateColumn Field=@nameof(Product.TotalSales) Type="AggregateType.Custom"> 
                    <FooterTemplate> 
                        @{ 
                            <div> 
                                <p>Total : </p> 
                            </div> 
                        } 
                    </FooterTemplate> 
                </GridAggregateColumn> 
            </GridAggregateColumns> 
        </GridAggregate> 
    </GridAggregates> 
 
    protected void ExcelAggregateTemplateInfo(ExcelAggregateEventArgs arg) 
    { 
        if (arg.Column.Field.Equals("TotalSales")) 
        { 
            arg.Cell.Value = "Total : "; 
        }         
    } 
 
    protected void PdfAggregateTemplateInfo(PdfAggregateEventArgs arg) 
    {         
        if (arg.Column.Field.Equals("TotalSales")) 
        { 
            arg.Cell.Value = "Total : "; 
        } 
   } 
 
 
Reference :  
 
Please get back to us if you need further assistance. 
 
Regards, 
Renjith R 



DR Daniel Reibelt July 13, 2022 10:10 PM UTC

This example is fine for static content, can you include a sample that performs agregation in the custom type, 



VN Vignesh Natarajan Syncfusion Team July 14, 2022 06:20 AM UTC

Hi Daniel,


Greetings from Syncfusion support.


Query:” This example is fine for static content, can you include a sample that performs agregation in the custom type, 



As requested, we have prepared a sample to perform calculations in a custom aggregate and export the aggregate to excel/pdf format. Refer to the below sample for your reference


Please get back to us if you have further queries.


Regards,

Vignesh Natarajan


Attachment: ServerApp_6f4e7f9b.zip

Loader.
Up arrow icon