This is a migrated thread and some comments may be shown as answers.

Exporting custom aggregates

2 Answers 47 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Yaroslav asked on 06 Aug 2012, 07:40 AM
I have grid with custom aggregate in one column and export to PDF/Excel abilities. When I view in browser aggregation works ok, but there is no aggregation in exported documents. Here is my code:

<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowPaging="True"
    OnItemCreated="RadGrid1ItemCreated" OnNeedDataSource="RadGrid1NeedDataSource"
    OnCustomAggregate="RadGrid1CustomAggregate" OnExcelMLExportRowCreated="RadGrid1ExcelMlExportRowCreated"
    OnExcelMLExportStylesCreated="RadGrid1ExcelMlExportStylesCreated" AllowFilteringByColumn="True"
    AllowSorting="True" CellSpacing="0" OnItemDataBound="RadGrid1ItemDataBound">
    <ExportSettings ExportOnlyData="true" IgnorePaging="true" OpenInNewWindow="true">
        <Excel Format="ExcelML" />
        <Pdf PageTitle="Charity Print-Out" Title="Charity Print-Out" PageHeight="210mm" PageWidth="500mm"
            DefaultFontFamily="Arial Unicode MS" PageBottomMargin="20mm" PageTopMargin="20mm"
            PageLeftMargin="20mm" PageRightMargin="20mm" />
    <PagerStyle Mode="NextPrevAndNumeric" />
    <MasterTableView AutoGenerateColumns="False" DataKeyNames="DonationId" CommandItemDisplay="Top"
        Width="100%" AllowPaging="True" NoDetailRecordsText="" NoMasterRecordsText=""
        ShowGroupFooter="true" UseAllDataFields="True">
        <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="False"
            ShowRefreshButton="False" ShowExportToPdfButton="True" />
        <PagerStyle Mode="NextPrevAndNumeric" />
            <telerik:GridBoundColumn DataField="CHR_CHARITY_NAME" HeaderText="Charity Name" ReadOnly="True"
                UniqueName="CHR_CHARITY_NAME" Visible="False" />
            <telerik:GridBoundColumn DataField="DonationInternalId" HeaderText="Client Donation ID"
                ReadOnly="True" UniqueName="DonationInternalId" />
            <telerik:GridBoundColumn DataField="DonorName" HeaderText="Donor's Name" ReadOnly="True"
                UniqueName="DonorName" />
            <telerik:GridBoundColumn DataField="DonorAddress" HeaderText="Donor's Address" ReadOnly="True"
                UniqueName="DonorAddress" />
            <telerik:GridBoundColumn DataField="EmailAddress" HeaderText="Email" ReadOnly="True"
                UniqueName="EmailAddress" />
            <telerik:GridBoundColumn DataField="PermissionToContact" HeaderText="Permission To Contact"
                ReadOnly="True" UniqueName="PermissionToContact" />
            <telerik:GridBoundColumn DataField="DateOfDonation" HeaderText="Donation Date" ReadOnly="True"
                UniqueName="DateOfDonation" />
            <telerik:GridBoundColumn DataField="NotesToCharity" HeaderText="Donor Notes" ReadOnly="True"
                UniqueName="NotesToCharity" />
            <telerik:GridBoundColumn DataField="DonationAmount" HeaderText="Donation Amount"
                ReadOnly="True" UniqueName="DonationAmount" DataFormatString="{0:C}" Aggregate="Custom"
                FooterText=" " />
                    <telerik:GridGroupByField FieldName="CHR_CHARITY_NAME" />
                    <telerik:GridGroupByField FieldName="CHR_CHARITY_NAME" HeaderText=" " HeaderValueSeparator=" " />
                    <telerik:GridGroupByField FieldName="CHR_BN_NUMBER" HeaderText="-" HeaderValueSeparator=" " />

And code-behind:

protected void RadGrid1CustomAggregate(object sender, GridCustomAggregateEventArgs e)
    if (e.Item.DataItem == null)
    const string result = "<table style=\"border-collapse:collapse;text-align:left;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">" +
                          "<tr><td style=\"text-align:left;\">Total Donations:</td><td>${0}</td></tr>" +
                          "<tr><td style=\"text-align:left;\">Processing & Transaction Fees @ 8%:</td><td>${1}</td></tr>" +
                          "<tr><td style=\"text-align:left;\">Net Donation Amount:</td><td>${2}</td></tr>" +
    double totalDonations = 0, netDonationAmount = 0, fees = 0;
    foreach (DataRow row in dataTable.Rows)
        if (row["CHR_CHARITY_NAME"].ToString() != ((DataRowView)e.Item.DataItem).Row.ItemArray[0].ToString())
        if (row["DonationAmount"] != null)
            totalDonations += (double)row["DonationAmount"];
        if (row["NetDonationAmount"] != null)
            netDonationAmount += (double)row["NetDonationAmount"];
        if (row["Fees"] != null)
            fees += (double)row["Fees"];
    e.Result = String.Format(result, totalDonations.ToString("0.00"), fees.ToString("0.00"), netDonationAmount.ToString("0.00"));

What I am doing wrong?

2 Answers, 1 is accepted

Sort by
Top achievements
Rank 1
answered on 07 Aug 2012, 06:36 PM
Sorry for up, but I still don't solve this problem. Could you please help me?
Telerik team
answered on 10 Aug 2012, 12:43 PM
Hello Yaroslav,

Custom aggregates won't be shown when exporting to ExcelML format as it takes the data directly from the datasource, ignoring your changes. You could either use another format or add the changed data manually in ExcelMLRowCreated or ExcelMLWorkbookCreated events.

Best regards,
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Asked by
Top achievements
Rank 1
Answers by
Top achievements
Rank 1
Telerik team
Share this question