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

Problem exporting to excel when rows are grouped

5 Answers 70 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 02 Apr 2011, 03:58 AM
Hi there.

I have a grid with sorting, filtering, grouping and exporting to excel (html format) enabled. Everything works fine but I can only export to excel if i have not done any sorting, filtering or grouping.

When I try to export, the command bar and filter bar disappear and the last column loses some of its formatting but no exceptions seem to be thrown. I'm using 2010.2.929.35 in DotNetnuke 5.6.1.

Thanks in advance for any suggestions.
Cheers
Chris

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CompanyReports_Scoreboard.ascx.cs" Inherits="Revd.Modules.Managers.CompanyReports_Scoreboard" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" />
<table class="FFTableView100pc">
    <tr>
        <td class="FFTableHeader">
            Scoreboard
        </td>
    </tr>
    <tr>
        <td class="FFGeneral">
            The Scoreboard shows all participants and their scores.
        </td>
    </tr>
    <tr>
        <td>
            <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" OnItemCommand="RadGrid1_ItemCommand" AllowPaging="True" AllowSorting="True" DataSourceID="SqlDataSource1" GridLines="None" ShowGroupPanel="True" OnGridExporting="RadGrid1_Exporting" OnItemDataBound="RadGrid1_ItemDataBound" PageSize="20">
                <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default">
                </HeaderContextMenu>
                <MasterTableView AutoGenerateColumns="False" DataKeyNames="TenantID" DataSourceID="SqlDataSource1" CommandItemDisplay="Bottom">
                    <CommandItemSettings ShowAddNewRecordButton="false" ShowExportToExcelButton="true" ExportToExcelText="Export to Excel" ShowRefreshButton="true" RefreshText="Refresh this view" />
                    <RowIndicatorColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn>
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </ExpandCollapseColumn>
                    <Columns>
                        <telerik:GridBoundColumn DataField="TenantID" DataType="System.Int32" HeaderText="TenantID" ReadOnly="True" SortExpression="TenantID" UniqueName="TenantID" Visible="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn Groupable="false" DataField="TenantName" HeaderText="Customer Name" SortExpression="TenantName" UniqueName="TenantName">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="PartnerID" DataType="System.Int32" HeaderText="PartnerID" SortExpression="PartnerID" UniqueName="PartnerID" Visible="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="TenantClassification1" HeaderText="Company Size" SortExpression="TenantClassification1" UniqueName="TenantClassification1">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="TenantClassification2" HeaderText="Industry Sector" SortExpression="TenantClassification2" UniqueName="TenantClassification2">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="TenantClassification3" HeaderText="Location" SortExpression="TenantClassification3" UniqueName="TenantClassification3">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="ReportStatus" DataType="System.Byte" HeaderText="Status" SortExpression="ReportStatus" UniqueName="ReportStatus" AllowFiltering="false">
                        </telerik:GridBoundColumn>
                        <telerik:GridNumericColumn Groupable="false" NumericType="Percent" DataFormatString="{0:#%}" DataField="Score" DataType="System.Decimal" HeaderText="Score" SortExpression="Score" UniqueName="Score" ItemStyle-Width="70px" FilterControlWidth="22px">
                        </telerik:GridNumericColumn>
                    </Columns>
                </MasterTableView>
                <ClientSettings AllowDragToGroup="True" EnableAlternatingItems="false" EnableRowHoverStyle="true">
                </ClientSettings>
                <ExportSettings ExportOnlyData="true" FileName="MyFile" Excel-Format="Html" OpenInNewWindow="true" HideStructureColumns="true" IgnorePaging="true" />
            </telerik:RadGrid>
 
            <script type="text/javascript">
                function onRequestStart(sender, args) {
                    if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
                            args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||
                            args.get_eventTarget().indexOf("ExportToCsvButton") >= 0) {
                        args.set_enableAjax(false);
                    }
                }
            </script>
 
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>" SelectCommand="SELECT dbo.__FFTenant.TenantID, dbo.__FFTenant.TenantName, dbo.__FFTenant.PartnerID, dbo.__FFTenant.TenantClassification1, dbo.__FFTenant.TenantClassification2, dbo.__FFTenant.TenantClassification3, dbo._FFFrameworkReport.ReportStatus, dbo._FFFrameworkReport.Score FROM dbo._FFFrameworkReport INNER JOIN dbo.__FFTenant ON dbo._FFFrameworkReport.TenantID = dbo.__FFTenant.TenantID WHERE (dbo.__FFTenant.PartnerID = @UserIsPartnerTenantID) ORDER BY dbo.__FFTenant.TenantName">
                <SelectParameters>
                    <asp:SessionParameter Name="UserIsPartnerTenantID" SessionField="UserIsPartnerTenantID" />
                </SelectParameters>
            </asp:SqlDataSource>
        </td>
    </tr>
    <tr>
        <td>
            <asp:HyperLink ID="lnkCompanyReports" CssClass="FFLinkCommand" runat="server"><img src="<%= skinpath %>images/_FFgoback.png" class="FFImgCommand" />Go to the Company Reports Page</asp:HyperLink>
        </td>
    </tr>
</table>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke.Entities.Modules;
using Telerik.Web.UI;
using Revd.Common.Utilities;
using Revd.DataAccess;
 
namespace RevolutionId.Modules.Managers
{
    public partial class CompanyReports_Scoreboard : PortalModuleBase
    {
        public static string skinpath = "";
        protected void Page_Load(object sender, EventArgs e)
        {
           if (!IsPostBack)
           {
               SessionService.UserIsPartnerTenantID = 30;
               skinpath = base.PortalSettings.ActiveTab.SkinPath;
               lnkCompanyReports.NavigateUrl = _DataUtilities.GetURL_General("", "", 0, _DataUtilities.PageNames.CompanyReports);
           }
        }
 
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem gridItem = (GridDataItem)e.Item;
                if (!e.Item.IsInEditMode)
                {
                    int myValue = Convert.ToInt32(DataBinder.Eval(gridItem.DataItem, "ReportStatus"));
                    if (myValue == 0)
                    {
                        gridItem["ReportStatus"].Text = "Work in Progress";
                    }
                    else if (myValue == 1)
                    {
                        gridItem["ReportStatus"].Text = "Completed";
                    }
                    else
                    {
                        gridItem["ReportStatus"].Text = "Don't know";
                    }
                }
            }
        }
 
        protected void RadGrid1_Exporting(object source, Telerik.Web.UI.GridExportingArgs e)
        {
            try
            {
            }
            catch (Exception ex)
            {
                DisplayMessage("Problem occurred. Reason: " + ex.Message);
            }
        }
 
        protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            try
            {
                if (e.CommandName == "PerformInsert")
                {
                }
            }
            catch (Exception ex)
            {
                DisplayMessage("Problem occurred. Reason: " + ex.Message);
            }
        }
 
        private void DisplayMessage(string text)
        {
            RadGrid1.Controls.Add(new LiteralControl(text));
        }
    }
}

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Apr 2011, 04:14 AM
Hello Chrisl,

You need to set ExportOnlyData="false" to include all the controls in the exported file.

Thanks,
Princy.
0
Chris
Top achievements
Rank 1
answered on 07 Apr 2011, 03:55 AM
Thanks for your response Princy.

Unfortunately that makes no difference. Same problem occurs.
0
Daniel
Telerik team
answered on 07 Apr 2011, 10:11 PM
Hello Chris,

I believe that for some reason the code that cancels the ajax request does not kick in after you perform these operations. Could you please try to temporary disable AJAX so that we can check whether my assumption is correct?
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnableAJAX="false"
...

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Chris
Top achievements
Rank 1
answered on 07 Apr 2011, 11:40 PM
Hi Daniel.

At first your suggestion didn't make any difference. But then I editted this dotnetnuke module's Supports Partial Rendering? setting to false and it worked as expected.

Just to mention also, I didn't have the <ClientEvents OnRequestStart="onRequestStart" /> in the page so the javascript for disabling ajax will not have been firing.

So how can i get this working with ajax?

Thanks
0
Daniel
Telerik team
answered on 12 Apr 2011, 09:58 PM
Hello Chris,

Please try the following code and let me know whether this helps.
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(initializeRequestHandler);
function initializeRequestHandler(sender, args)
{
    if (args.get_postBackElement().id.indexOf("THE_ID_OF_YOUR_EXPORT_BUTTON") != -1)
    {
        args.set_cancel(true);
        sender._form["__EVENTTARGET"].value = args.get_postBackElement().id.replace(/\_/g, "$");
        sender._form["__EVENTARGUMENT"].value = "";
        sender._form.submit();
        return;
    }
}

Regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Chris
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or