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

[Solved] Problem exporting grid content to EXCEL/PDF using telerik mechanism

7 Answers 234 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Leonid Raichman
Top achievements
Rank 1
Leonid Raichman asked on 12 Jan 2010, 07:41 PM
Hi , I need a help with exporting to excel / pdf.
I dont know why I cant enter event handler of OnGridExporting event. I have enabled built in command for exporting and added an appropriate event in grid mark up definition.the problem that onCommand event handler is intercepting OnGridExporting event.
please see attached markup file and try to help me . I am using telerik 2009 Q3 version . 

Thanks ! 
<body class="BODY"
    <form runat="server" id="mainForm" method="get"
    <telerik:RadScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" /> 
    <!-- content start --> 
    <asp:CheckBox ID="CheckBox1" Text="Allow multi column sorting" Checked="true" runat="server" 
        onclick="toggleAllowMultiColumnSorting(this, event);" /> 
    <telerik:RadDockLayout runat="server" ID="RadDockLayout1"
        <table width="100%" border="0"
            <tr> 
                <td align="center" rowspan="1" valign="middle" colspan="2"
                    <telerik:RadDockZone ID="RadDockZoneTop" runat="server" Orientation="Vertical"
                        <telerik:RadDock ID="RadDockSearch" runat="server" Title="חיפוש" EnableAnimation="true" 
                            EnableRoundedCorners="true" Resizable="false" DefaultCommands="ExpandCollapse" 
                             > 
                            <ContentTemplate> 
                                <table width="100%"
                                    <tr align="center" valign="middle"
                                        <td> 
                                            <asp:Panel ID="searchPanel" runat="server"
                                                <!-- Search controls Start --> 
                                                <br /> 
                                                <input id="txtSearch" size="40" /> 
                                                <input id="btnSearch" type="button" onclick="SearchCommand(document.getElementById('txtSearch').value);" 
                                                    value="Search" /> 
                                                <br /> 
                                                <br /> 
                                                <!-- Search controls End --> 
                                            </asp:Panel> 
                                        </td> 
                                    </tr> 
                                </table> 
                            </ContentTemplate> 
                        </telerik:RadDock> 
                    </telerik:RadDockZone> 
                </td> 
                <td align="center" valign="middle"
                </td> 
            </tr> 
            <tr>  
                <td> 
                    <telerik:RadDockZone ID="RadDockZoneMiddleLeft" runat="server" Orientation="Vertical"
                        <telerik:RadDock ID="RadDockGrid" runat="server" Title="תוצאות חיפוש" EnableAnimation="true" 
                            EnableRoundedCorners="true" Resizable="false" DefaultCommands="ExpandCollapse"
                            <ContentTemplate> 
                           
                                
                                <telerik:RadGrid ID="RadGrid1" Visible="true" EnableViewState="false" runat="server" 
                                    OnInit="RadGrid1_Init" AllowPaging="true" AllowSorting="True" GridLines="None" 
                                    ShowGroupPanel="true" ShowFooter="true" ShowStatusBar="true" ShowHeader="true" 
                                    AutoGenerateColumns="false" AllowFilteringByColumn="true" OnColumnCreating="RadGrid1_ColumnCreating" 
                                    OnGridExporting="RadGrid1_GridExporting"
                                    <ItemStyle Wrap="false" /> 
                                    <MasterTableView Width="100%" AllowMultiColumnSorting="true" TableLayout="Fixed" 
                                        GroupLoadMode="Server" GroupsDefaultExpanded="true" AllowFilteringByColumn="true" 
                                        CommandItemDisplay="Top"
                                        <Columns> 
                                            <telerik:GridBoundColumn Visible="false" DataField="Id" HeaderText="מזהה ייחודי" 
                                                DataType="System.String" HeaderStyle-Width="80px" FilterControlWidth="40px"
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="Title" HeaderText="כותרת" DataType="System.String" 
                                                HeaderStyle-Width="400px" FilterControlWidth="370px"
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="Agency" HeaderText="סוכנות" DataType="System.String" 
                                                HeaderStyle-Width="100px" FilterControlWidth="60px"
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="EmployeeId" HeaderText="מזהה עובד" DataType="System.Int32" 
                                                HeaderStyle-Width="80px" FilterControlWidth="40px"
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="ClearanceLevel" HeaderText="רמת אישור" DataType="System.String" 
                                                HeaderStyle-Width="80px" FilterControlWidth="40px"
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn DataField="SiteId" HeaderText="אתר" DataType="System.String" 
                                                HeaderStyle-Width="80px" FilterControlWidth="40px"
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridBoundColumn Visible="false" DataField="InternalURI" HeaderText="קישור" 
                                                DataType="System.String" HeaderStyle-Width="80px" FilterControlWidth="40px"
                                            </telerik:GridBoundColumn> 
                                            <telerik:GridTemplateColumn Visible="false" DataField="InternalURI" HeaderText="קישור" 
                                                UniqueName="InternalURITemplate" Aggregate="Count" GroupByExpression="InternalURI Group By InternalURI" 
                                                DataType="System.String"
                                                <ItemTemplate> 
                                                    <asp:Label ID="lblInternalURI" runat="server" Text='<%#Eval("InternalURI") %>'
                                                    </asp:Label> 
                                                </ItemTemplate> 
                                            </telerik:GridTemplateColumn> 
                                            <telerik:GridDateTimeColumn DataField="CreationDate" HeaderText="תאריך יצירה" DataType="System.DateTime " 
                                                HeaderStyle-Width="80px" FilterControlWidth="40px" DataFormatString="{0:dd/MM/yyyy}"
                                            </telerik:GridDateTimeColumn> 
                                            <telerik:GridBoundColumn DataField="Receptiondate" HeaderText="תאריך קבלה" DataType="System.DateTime" 
                                                HeaderStyle-Width="80px" FilterControlWidth="40px" DataFormatString="{0:dd/MM/yyyy}"
                                            </telerik:GridBoundColumn> 
                                        </Columns> 
                                        <CommandItemSettings ShowExportToExcelButton="true" ShowExportToPdfButton="true" /> 
                                        <PagerStyle AlwaysVisible="true" Position="TopAndBottom" Mode="NextPrevAndNumeric" /> 
                                    </MasterTableView> 
                                    <ClientSettings AllowGroupExpandCollapse="true" AllowDragToGroup="true" > 
                                        <Selecting AllowRowSelect="True" EnableDragToSelectRows="true" /> 
                                        <Resizing AllowRowResize="false" AllowColumnResize="false" EnableRealTimeResize="True" 
                                            ResizeGridOnColumnResize="True" /> 
                                        <ClientEvents OnCommand="RadGrid1_Command" OnRowDataBound="RadGrid1_RowDataBound" 
                                            OnRowDblClick="RowDblClick" OnRowSelected="RowSelected" OnKeyPress="KeyPress" /> 
                                    </ClientSettings> 
                                    <GroupingSettings ShowUnGroupButton="true" /> 
                                    <FilterMenu EnableTheming="True"
                                        <CollapseAnimation Duration="200" Type="OutQuint" /> 
                                    </FilterMenu> 
                                </telerik:RadGrid> 
                            </ContentTemplate> 
                        </telerik:RadDock> 
                    </telerik:RadDockZone> 
                </td> 
            </tr> 
            <tr> 
                <td align="center" valign="top"
                    <telerik:RadDockZone ID="RadDockZoneBottom" runat="server" Orientation="Vertical" 
                        Width="100%" Height="100%"
                        <telerik:RadDock ID="RadDockPreviewBottom" runat="server" Title="צפייה מקדימה" EnableAnimation="true" 
                            EnableRoundedCorners="true" Resizable="false" DefaultCommands="ExpandCollapse"
                            <ContentTemplate> 
                                <div id="PreviewDiv" dir="ltr" title="צפייה מקדימה"
                                </div> 
                            </ContentTemplate> 
                        </telerik:RadDock> 
                    </telerik:RadDockZone> 
                </td> 
            </tr> 
        </table> 
    </telerik:RadDockLayout> 
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" /> 
    <br /> 
    <asp:Button ID="clrFilters" runat="server" Text="Clear filters" OnClick="clrFilters_Click"
    </asp:Button> 
    <br /> 
    Events: 
    <asp:Panel ID="Panel1" Style="height: 200px; overflow: auto; padding: 15px;" CssClass="module" 
        runat="server"
    </asp:Panel> 
    <!-- content end --> 
    </form> 
</body> 


code behind : 

   protected void RadGrid1_GridExporting(object source, GridExportingArgs e) 
        { 
          
unable to get here ! ! !     
 
        } 

7 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 15 Jan 2010, 04:49 PM
Hello Leonid,

I suppose you cancel the command in the OnCommand handler.
Please note that exporting with client-side binding is not supported.

I recommend you examine the following help topic:
RadGrid export overview

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Leonid Raichman
Top achievements
Rank 1
answered on 15 Jan 2010, 07:04 PM
Hi , Thanks for your reply .

I  am using a PAGE METHODS to bind a grid . 
I have a button on my page which is calling to a PAGE METHOD which brings a data to the grid .

Then I am using OnCommand client event in order to process paging / sorting / filtering via some other Page Method . 
If there is any way to use telerik export mechanism in this case ? 



0
Daniel
Telerik team
answered on 19 Jan 2010, 06:11 PM
Hello Leonid,

The only way to export RadGrid when using client-side data binding, is to populate it on the server before exporting.

As to the OnCommand event - could you please post the contents of your RadGrid1_Command event handler?

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Leonid Raichman
Top achievements
Rank 1
answered on 20 Jan 2010, 05:52 AM
 function RadGrid1_Command(sender, args) { 
             
 
                args.set_cancel(true); 
 
                var pageSize = sender.get_masterTableView().get_pageSize(); 
 
                var sortExpressions = sender.get_masterTableView().get_sortExpressions(); 
                var filterExpressions = sender.get_masterTableView().get_filterExpressions(); 
 
                var currentPageIndex = sender.get_masterTableView().get_currentPageIndex(); 
 
                if (args.get_commandName() == "Filter") 
                    currentPageIndex = 0
 
                if (args.get_commandName() == "Page") { 
                    var table = sender.get_masterTableView(); 
                    // clear selected row from previous page 
                    table.clearSelectedItems(); 
                } 
 

when I am clicking on ExportToExcel/PDF button on the grid , I can see that 
args.get_commandName() is "ExportToExcel"/"ExportToPdf" . 
0
Daniel
Telerik team
answered on 21 Jan 2010, 07:00 PM
Hello Leonid,

The Export command won't fire when you cancel it explicitly. You could modify your code as demonstrated below:
<script type="text/javascript">
    function RadGrid1_Command(sender, args)
    {
        if (args.get_commandName().indexOf("Export") != -1)
            return true;
        args.set_cancel(true);
        var pageSize = sender.get_masterTableView().get_pageSize();
        var sortExpressions = sender.get_masterTableView().get_sortExpressions();
        var filterExpressions = sender.get_masterTableView().get_filterExpressions();
        var currentPageIndex = sender.get_masterTableView().get_currentPageIndex();
        if (args.get_commandName() == "Filter")
            currentPageIndex = 0;
        if (args.get_commandName() == "Page")
        {
            var table = sender.get_masterTableView();
            // clear selected row from previous page
            table.clearSelectedItems();
        }
    }
</script>

Regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Leonid Raichman
Top achievements
Rank 1
answered on 25 Jan 2010, 06:02 AM
HI , thanks for your replay .

It does not help . nothing happened , except that grid refreshed it self and displayed an empty grid . 

I changed the code according to your suggestion . In my mark up , grid has server side  onexportingevent subscription, which I still can not enter . please assist.  
0
Daniel
Telerik team
answered on 28 Jan 2010, 10:15 AM
Hello Leonid,

Please download the sample project attached to this post and let me know whether it behaves as expected on your end.

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Leonid Raichman
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Leonid Raichman
Top achievements
Rank 1
Share this question
or