Remove aggrigation type on pdf/excel export

Hi, 


We are using Syncfusion blazor grid in one of our applications. We are having some data and aggrigations in the footer. In the browser it looks and works nice just wandering is it possible to remove the aggrigation name/type in pdf/excel export. For example dont want to view this "Sum:{aggrigation.value}" just the value in the footer.

Here is some example code:


@page "/aggregate"

@using Syncfusion.Blazor.Grids

@using Syncfusion.Blazor.Navigations;


<SfGrid DataSource="@Orders" ID="OrdersGrid" @ref="ordersGrid" AllowPaging="true" AllowSorting="true"

        Toolbar="@(new List<string>() { "ExcelExport", "PdfExport" })" AllowExcelExport="true" AllowPdfExport="true">

    <GridEvents OnToolbarClick="ToolbarClickHandler" TValue="Order"></GridEvents>

    <GridAggregates>

        <GridAggregate>

            <GridAggregateColumns>

                <GridAggregateColumn Field="@nameof(Order.Freight)" Type="AggregateType.Sum" Format="C2"></GridAggregateColumn>

            </GridAggregateColumns>

        </GridAggregate>

    </GridAggregates>

    <GridColumns>

        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>

        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>

        <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn>

        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>

    </GridColumns>

</SfGrid>


@code{

    public List<Order> Orders { get; set; }

    public SfGrid<Order> ordersGrid;


    protected override void OnInitialized()

    {

        Orders = Enumerable.Range(1, 75).Select(x => new Order()

        {

            OrderID = 1000 + x,

            CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],

            Freight = 2.1 * x,

            OrderDate = DateTime.Now.AddDays(-x),

        }).ToList();

    }


    public async Task ToolbarClickHandler(ClickEventArgs args)

    {

        if (args.Item.Id == "OrdersGrid_excelexport")

        {

            ExcelExportProperties excelProperties = new() { FileName = "SomeFile.xlsx" };

            await ordersGrid.ExcelExport(excelProperties);

        }

        else if (args.Item.Id == "OrdersGrid_pdfexport")

        {

            PdfExportProperties pdfProperties = new() { FileName = "SomeFile.pdf" };

            await ordersGrid.PdfExport(pdfProperties);

        }

    }


    public class Order

    {

        public int? OrderID { get; set; }

        public string CustomerID { get; set; }

        public DateTime? OrderDate { get; set; }

        public double? Freight { get; set; }

    }

}


5 Replies

RN Rahul Narayanasamy Syncfusion Team December 3, 2021 12:25 PM UTC

Hi Svetozar, 
 
Greetings from Syncfusion. 
 
Query: Remove aggrigation type on pdf/excel export - For example dont want to view this "Sum:{aggrigation.value}" just the value in the footer. 
 
We have validated your query and you want to remove the aggregate value in footer in PDF and Excel document. You can achieve your requirement by using ExcelAggregateTemplateInfo and PdfAggregateTemplateInfo event of the Grid. Find the below code snippets and sample for your reference. 
 
 
<SfGrid DataSource="@Orders" ID="OrdersGrid" @ref="ordersGrid" AllowPaging="true" AllowSorting="true" 
        Toolbar="@(new List<string>() { "ExcelExport", "PdfExport" })" AllowExcelExport="true" AllowPdfExport="true"> 
    <GridEvents ExcelAggregateTemplateInfo="ExcelAggregateTemplateInfoHandler" 
               PdfAggregateTemplateInfo="PdfAggregateTemplateInfoHandler" OnToolbarClick="ToolbarClickHandler" TValue="Order"></GridEvents> 
    <GridAggregates> 
        <GridAggregate> 
            <GridAggregateColumns> 
                <GridAggregateColumn Field="@nameof(Order.Freight)" Type="AggregateType.Sum" Format="C2"> 
                    <FooterTemplate> 
                        @{ 
                            var aggregate = (context as AggregateTemplateContext); 
                            <div> 
                                <p>Sum: @aggregate.Sum</p> 
                            </div> 
                        } 
                    </FooterTemplate> 
                </GridAggregateColumn> 
            </GridAggregateColumns> 
        </GridAggregate> 
    </GridAggregates> 
    <GridColumns> 
        . ..  
    </GridColumns> 
</SfGrid> 
 
@code{ 
    . . . 
    public void ExcelAggregateTemplateInfoHandler(ExcelAggregateEventArgs args) 
    { 
        if (args.Column.Field == "Freight") 
        { 
            args.Cell.Value = "";       //customize the aggregate cell value here 
        } 
        // Here you can customize your code 
    } 
    public void PdfAggregateTemplateInfoHandler(PdfAggregateEventArgs args) 
    { 
        // Here you can customize your code 
        if (args.Column.Field == "Freight") 
        { 
            args.Cell.Value = "";       //customize the aggregate cell value here 
        } 
    } 
 
} 
 
 
 
Please let us know if you have any concerns. 
 
Regards, 
Rahul 
 



SR Svetozar Rusev December 7, 2021 10:31 AM UTC

Thank you very much.

It works like a charm


Regards,

Svetozar



RS Renjith Singh Rajendran Syncfusion Team December 8, 2021 07:15 AM UTC

Hi Svetozar, 
 
Thanks for your update. Please get back to us if you need further assistance. 
 
Regards, 
Renjith R 



JB Josh Barrineau September 28, 2023 10:16 PM UTC

Hi, sorry to post on an old thread but this is the closest issue I could find that matched what is happening to me. The original issue on this thread is happening to me, the difference is I have two GridAggregates that are simple Sum type with no template, and one GridAggregate with a template.

Using ExcelAggregateTemplateInfoHandler only seems to affect the GridAggregate with the template defined, which makes sense, and I can remove the "Sum:" text from it, but I can't seem to find a way to remove the "Sum:" text from the GridAggregates that do not have a template. The other action ExcelQueryCellInfoHandler doesn't work either.



SP Sarveswaran Palani Syncfusion Team October 3, 2023 04:27 AM UTC

Hi Josh,


Greeting from Syncfusion support.


We would like to clarify you that we have only the ExcelAggregateTemplateInfo event to customize the DataGrid aggregate content in Excel File. Currently , we don't have any support to handle aggregates without a template. Kindly refer the attached UG documentation to resolve your issues.


Reference Link: https://blazor.syncfusion.com/documentation/datagrid/aggregates
https://blazor.syncfusion.com/documentation/datagrid/events#excelaggregatetemplateinfo


Please get back to us if you have further queries.

Regards,
Sarvesh



Loader.
Up arrow icon