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

Radgrid GroupBy Totals are not Exporting to Excel

4 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Satz
Top achievements
Rank 1
Satz asked on 26 Dec 2013, 02:17 PM
Hi,

Radgrid group by footer Calculations(calculated based on Headercontext aggregates menu)  are not exporting into excel.  Columns are auotGenerated and the data is coming from stored procedure dynamically.


Kindly guide me on this issue.

Best Regards,
satz

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 26 Dec 2013, 02:26 PM
Hi Satz,

Below is a sample code snippet that i tried , which works fine at my end. Please try and provide your full code snippet if this doesn't help.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" ShowFooter="true" EnableHeaderContextMenu="true" EnableHeaderContextFilterMenu="true" >
    <ExportSettings ExportOnlyData="true"></ExportSettings>
    <MasterTableView DataKeyNames="OrderID" CommandItemDisplay="Top" ShowGroupFooter="true" EnableHeaderContextAggregatesMenu="true" EnableHeaderContextMenu="true">
    <CommandItemSettings ShowExportToExcelButton="true" />    
        <GroupByExpressions>
            <telerik:GridGroupByExpression>
                <GroupByFields>
                    <telerik:GridGroupByField FieldName="ShipCity" />
                </GroupByFields>
                <SelectFields>
                    <telerik:GridGroupByField FieldName="ShipCity" HeaderText="ShipCity" />
                </SelectFields>
            </telerik:GridGroupByExpression>
        </GroupByExpressions>
    </MasterTableView>
</telerik:RadGrid>

Thanks,
Princy
0
Satz
Top achievements
Rank 1
answered on 26 Dec 2013, 03:07 PM

Below is my sample code.

<telerik:RadGrid runat="server" ID="radgrid"
  
                ShowFooter="True" CssClass="RadGrid"
  
                OnItemCommand="radgrid_ItemCommand"
  
                OnColumnCreated="radgrid_ColumnCreated"
  
                OnNeedDataSource="radgrid_NeedDataSource"
  
                OnPreRender="radgrid_PreRender"
  
                AllowFilteringByColumn="True" AllowSorting="True"
  
                AutoGenerateColumns="true" Width="850px" Height="600px"
  
                ShowGroupPanel="True" AllowPaging="True" CellSpacing="0" GridLines="None" PageSize="50" PagerStyle-Visible="true">
 
                <ExportSettings HideStructureColumns="true">
 
                </ExportSettings>
 
                  <PagerStyle Mode="Advanced" AlwaysVisible="true"/>
 
                <MasterTableView ShowGroupFooter="true" AllowMultiColumnSorting="true" UseAllDataFields="true"
  
                    CommandItemDisplay="Top" EnableHeaderContextMenu="true" TableLayout="Auto" EnableHeaderContextAggregatesMenu="true">
 
                    <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="false"></CommandItemSettings>                
 
                    <GroupFooterTemplate>
 
                        <asp:Label runat="server" ID="OrderId" Visible="false" Text='<%# "OrderId: "+ VisibleColumn("OrderId")%>'></asp:Label>
 
                        <asp:Label runat="server" ID="PurchaseCost" Visible="false" Text='<%# "Cost: "+ VisibleColumn("Cost")%>'></asp:Label>
 
                        <asp:Label runat="server" ID="RefundAmount" Visible="false" Text='<%# "Refund Amount: "+ VisibleColumn("RefundAmount") %>'></asp:Label>
 
                                            </GroupFooterTemplate>
 
                </MasterTableView>
 
                <ClientSettings AllowDragToGroup="True" AllowColumnsReorder="True"
  
                    ClientEvents-OnColumnContextMenu="oncontextmenuClick">
 
                    <Scrolling AllowScroll="True"></Scrolling>
 
                </ClientSettings>
 
                  
  
                <GroupingSettings ShowUnGroupButton="true"></GroupingSettings>
 
            </telerik:RadGrid>
0
Princy
Top achievements
Rank 2
answered on 27 Dec 2013, 05:39 AM
Hi Satz,

Unfortunately i couldn't replicate the issue. The exporting feature works only with regular postbacks. This means, that the asynchronous postback should be canceled when performing an export.
More information on this topic is available below:
Export from ajaxified grid.
Below is the sample code snippet that i tried which works fine at my end, can you give this a try and see if this works:

ASPX:
<telerik:RadGrid ID="RadGrid1" ShowGroupPanel="true" AutoGenerateColumns="true" DataSourceID="SqlDataSource1"
    ShowFooter="True" runat="server" GridLines="None" AllowPaging="true" PageSize="7"
    Skin="Office2007" GroupingSettings-RetainGroupFootersVisibility="true">
    <MasterTableView ShowGroupFooter="true" CommandItemDisplay="Top" EnableHeaderContextMenu="true"
        TableLayout="Auto" EnableHeaderContextAggregatesMenu="true">
        <CommandItemSettings ShowExportToExcelButton="true" />
        <GroupHeaderTemplate>
            <!-- use the AggregatesValues collection to access the totals for each group header -->
            <asp:Label runat="server" ID="Label1" Text='<%# "Number of units: "+ (((GridGroupHeaderItem)Container).AggregatesValues["UnitsInStock"]) %>'
                Visible='<%# ((((GridGroupHeaderItem)Container).AggregatesValues["UnitsInStock"]) != null)%>'>
            </asp:Label>
            <asp:Label runat="server" ID="Label2" Text='<%# "Number of items in group: "+ (((GridGroupHeaderItem)Container).AggregatesValues["AvailableUnits"]) %>'
                Visible='<%# ((((GridGroupHeaderItem)Container).AggregatesValues["AvailableUnits"]) != null)%>'>
            </asp:Label>
            <asp:Label runat="server" ID="Label3" Text='<%# "Product name: "+Eval("ProductName") %>'
                Visible='<%# ((((GridGroupHeaderItem)Container).AggregatesValues["ProductName"]) != null)%>'></asp:Label>
            <asp:Label runat="server" ID="Label4" Text='<%# "Product price: "+ Eval("UnitPrice") %>'
                Visible='<%# ((((GridGroupHeaderItem)Container).AggregatesValues["UnitPrice"]) != null)%>'></asp:Label>
            <asp:Label runat="server" ID="Label5" Text='<%# "Total price: "+Eval("TotalPriceResult") %>'
                Visible='<%# ((((GridGroupHeaderItem)Container).AggregatesValues["TotalPriceResult"]) != null)%>'>
            </asp:Label>
        </GroupHeaderTemplate>
        <GroupFooterTemplate>
            Product count:
            <!-- the footer totals can be accessed using Eval() -->
            <asp:Label ID="Label6" runat="server" Text='<%#Eval("ProductName") %>'>
            </asp:Label>
            <!-- if you want to place cells inside the footer template, you should put a closing tag after the content of the first one (without an opening one) and skip the last </td> tag in the template.
    This is so because the template is rendered inside a single <td> and HTML validation would fail if you were to put regular <td></td> elements here-->
            </td>
            <td>
                Total units:
                <asp:Label ID="Label7" runat="server" Text='<%# Eval("UnitsInStock") %>'>
                </asp:Label>
            </td>
            <td>
                Total sum:
                <asp:Label ID="Label8" runat="server" Text='<%# Eval("UnitPrice") %>'>
                </asp:Label>
            </td>
            <td>
                Total price:
                <asp:Label ID="Label9" runat="server" Text='<%# Eval("TotalPriceResult") %>'>
                </asp:Label>
        </GroupFooterTemplate>
        <Columns>
            <telerik:GridCalculatedColumn HeaderText="Total Price" UniqueName="TotalPrice" DataType="System.Double"
                DataFields="UnitPrice, UnitsInStock" Expression="{0}*{1}" FooterText="Total : "
                Aggregate="Sum" />
        </Columns>
    </MasterTableView>
    <ClientSettings AllowDragToGroup="true" />
    <GroupingSettings ShowUnGroupButton="true" />
</telerik:RadGrid>

Thanks,
Princy
0
Satz
Top achievements
Rank 1
answered on 30 Dec 2013, 05:58 AM
Hi Princy,

The issue got resolved. I have explicitly specified Lable visible as false. 

And am setting the Lable visible in Pre Render Event which is a wrong . It should in the Item Data bound event.
<GroupFooterTemplate>
  
                        <asp:Label runat="server" ID="OrderId" Visible="false" Text='<%# "OrderId: "+ VisibleColumn("OrderId")%>'></asp:Label>
  
                        <asp:Label runat="server" ID="PurchaseCost" Visible="false" Text='<%# "Cost: "+ VisibleColumn("Cost")%>'></asp:Label>
  
                        <asp:Label runat="server" ID="RefundAmount" Visible="false" Text='<%# "Refund Amount: "+ VisibleColumn("RefundAmount") %>'></asp:Label>
  
                                            </GroupFooterTemplate>


Tags
Grid
Asked by
Satz
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Satz
Top achievements
Rank 1
Share this question
or