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

[Solved] Issue when exporting grid after filtering column

2 Answers 328 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike Nogen
Top achievements
Rank 1
Mike Nogen asked on 13 Jul 2009, 12:08 PM
Hello!

I´m using 2009.2.701.35 and are having trouble exporting to ExcelML when I have filtered the columns. There is no problems exporting on the default excel version or to Csv etc when colums are filtered.

The ExcelML export are working when the grid is NOT filtered.

There is also one strange bahavior that applies to all exports when using. It´s Paging. After exporting when using filter on colums and when I then select NO FILTER. The grid reloads the grid without paging and fill the grid with all rows from the database.

To reproduce this. Just take
1. New .ASPX page
2. Put an ScriptManager on the page
3. Put an RadAjaxManager on the page
4. Put an LinqDataSource on the page
5. Put an RadGrid on the page, activate AllowFilteringByColumn  Enable Paging and PageSize
6. Put a button on the .ASPX page
7. On the button event add this

RadGrid1.ExportSettings.Excel.Format = Telerik.Web.UI.GridExcelExportFormat.ExcelML;  
RadGrid1.ExportSettings.ExportOnlyData = true;  
RadGrid1.ExportSettings.IgnorePaging = true;  
RadGrid1.MasterTableView.ExportToExcel(); 

8. Load the page and filter a column
9. Export you data


2 Answers, 1 is accepted

Sort by
0
Mike Nogen
Top achievements
Rank 1
answered on 15 Jul 2009, 06:32 AM
This must be a bug. Even when I try the new build in Add RadGrid Template this issue exists. The below code is generated with the new Add template function.

Problems:
1. Export to ExcelML fail (works with Default Excel and Csv). If I just load my page and filter an column then click export the export of ExcelML fail.

2. After filtering a column and after exporting the grid. I set the filtered column to "NoFilter" the grid rebinds and show ALL data WITHOUT paging.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RadGridExportWebForm.aspx.cs" 
    Inherits="RadGridExportWebForm" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title></title>  
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" /> 
</head> 
<body> 
    <form id="form1" runat="server">  
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
        <ClientEvents OnRequestStart="RadAjaxManager1_RequestStart" /> 
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <div> 
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">  
 
            <script type="text/javascript">  
                function gridExport() {  
                    $find("<%= RadGrid1.ClientID %>").get_masterTableView().exportToExcel();  
                    return false;  
                }  
                function RadAjaxManager1_RequestStart(sender, args) {  
                    if (args.get_eventTarget() == "<%= RadGrid1.ClientID %>")  
                        args.set_enableAjax(false);  
                }  
            </script> 
 
        </telerik:RadScriptBlock> 
        <asp:Button OnClientClick="return gridExport()" ID="Button1" runat="server" Text="Export To Excel" /> 
        <asp:LinqDataSource ContextTypeName="PromotionCodeSalesStat.DataClasses1DataContext" 
            TableName="ViewGetPromotionCodesForProducts" ID="DataSource1" runat="server">  
        </asp:LinqDataSource> 
        <telerik:RadGrid DataSourceID="DataSource1" AllowFilteringByColumn="True" ID="RadGrid1" 
            runat="server" AllowPaging="True" PageSize="20" AutoGenerateColumns="False" GridLines="None">  
            <ExportSettings ExportOnlyData="True" FileName="ExportedRadGrid" OpenInNewWindow="True" 
                IgnorePaging="True" Excel-Format="ExcelML">  
                <Excel Format="ExcelML"></Excel> 
            </ExportSettings> 
            <MasterTableView DataSourceID="DataSource1">  
                <RowIndicatorColumn> 
                    <HeaderStyle Width="20px"></HeaderStyle> 
                </RowIndicatorColumn> 
                <ExpandCollapseColumn> 
                    <HeaderStyle Width="20px"></HeaderStyle> 
                </ExpandCollapseColumn> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="project" DataType="System.Int32" HeaderText="project" 
                        SortExpression="project" UniqueName="project">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="promo_code" HeaderText="promo_code" SortExpression="promo_code" 
                        UniqueName="promo_code">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="division" HeaderText="division" SortExpression="division" 
                        UniqueName="division">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="NbrOfOrders" DataType="System.Int32" HeaderText="NbrOfOrders" 
                        SortExpression="NbrOfOrders" UniqueName="NbrOfOrders">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="startDate" DataType="System.DateTime" HeaderText="startDate" 
                        SortExpression="startDate" UniqueName="startDate">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="endDate" DataType="System.DateTime" HeaderText="endDate" 
                        SortExpression="endDate" UniqueName="endDate">  
                    </telerik:GridBoundColumn> 
                </Columns> 
            </MasterTableView> 
        </telerik:RadGrid> 
    </div> 
    </form> 
</body> 
</html> 
 

The workaround to get the ExcelML export to work is to get rid of the LinqDataSource and replace it with a SqlDataSource . The issue with lost paging after setting the filtered column to NoFilter after export still exisit (Se workaround for paging at the end).

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RadGridExportWebForm1.aspx.cs" 
    Inherits="RadGridExportWebForm1" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title></title>  
    <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server" /> 
</head> 
<body> 
    <form id="form1" runat="server">  
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
        <ClientEvents OnRequestStart="RadAjaxManager1_RequestStart" /> 
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadGrid1">  
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <div> 
        <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">  
 
            <script type="text/javascript">  
                function gridExport() {  
                    $find("<%= RadGrid1.ClientID %>").get_masterTableView().exportToExcel();  
                    return false;  
                }  
                function RadAjaxManager1_RequestStart(sender, args) {  
                    if (args.get_eventTarget() == "<%= RadGrid1.ClientID %>")  
                        args.set_enableAjax(false);  
                }  
            </script> 
 
        </telerik:RadScriptBlock> 
        <asp:Button OnClientClick="return gridExport()" ID="Button1" runat="server" Text="Export To Excel" /> 
        <asp:SqlDataSource SelectCommand="SELECT * FROM [ViewGetPromotionCodesForProduct]" 
            ConnectionString="<%$ ConnectionStrings:SalesConnectionString %>" ID="DataSource1" 
            runat="server"></asp:SqlDataSource> 
        <telerik:RadGrid DataSourceID="DataSource1" ID="RadGrid1" AllowFilteringByColumn="True" 
            PageSize="20" AllowPaging="True" runat="server" AutoGenerateColumns="False" GridLines="None">  
            <ExportSettings ExportOnlyData="True" FileName="ExportedRadGrid" OpenInNewWindow="True" 
                IgnorePaging="True" Excel-Format="ExcelML">  
                <Excel Format="ExcelML"></Excel> 
            </ExportSettings> 
            <MasterTableView DataSourceID="DataSource1">  
                <RowIndicatorColumn> 
                    <HeaderStyle Width="20px"></HeaderStyle> 
                </RowIndicatorColumn> 
                <ExpandCollapseColumn> 
                    <HeaderStyle Width="20px"></HeaderStyle> 
                </ExpandCollapseColumn> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="project" DataType="System.Int32" HeaderText="project" 
                        SortExpression="project" UniqueName="project">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="promo_code" HeaderText="promo_code" SortExpression="promo_code" 
                        UniqueName="promo_code">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="division" HeaderText="division" SortExpression="division" 
                        UniqueName="division">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="NbrOfOrders" DataType="System.Int32" HeaderText="NbrOfOrders" 
                        SortExpression="NbrOfOrders" UniqueName="NbrOfOrders">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="startDate" DataType="System.DateTime" HeaderText="startDate" 
                        SortExpression="startDate" UniqueName="startDate">  
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn DataField="endDate" DataType="System.DateTime" HeaderText="endDate" 
                        SortExpression="endDate" UniqueName="endDate">  
                    </telerik:GridBoundColumn> 
                </Columns> 
            </MasterTableView> 
        </telerik:RadGrid> 
    </div> 
    </form> 
</body> 
</html> 
 

Workaround for getting paging back after export and setting the filtered column to "NoFilter" is to add this into the ItemCommand event.

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
        {  
            if (e.CommandName == RadGrid.FilterCommandName)   
            {  
                if (this.RadGrid1.AllowPaging == false)  
                {  
                    this.RadGrid1.MasterTableView.AllowPaging = true;  
                    this.RadGrid1.MasterTableView.Rebind();  
                }  
            }  
        } 


0
Daniel
Telerik team
answered on 16 Jul 2009, 12:40 PM
Hello Mike,

Could you please elaborate what do you mean by "Export to ExcelML fail"? Do you receive an error message?

I recommend you either set UseAllDataFields to your table view:
<MasterTableView UseAllDataFields="true" ... 

or set EnableLinqExpressions="false"
<telerik:RadGrid  
   ID="RadGrid1"  
   EnableLinqExpressions="false"  
   runat="server"  
   ... 

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Mike Nogen
Top achievements
Rank 1
Answers by
Mike Nogen
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or