Export to Pdf/Word/Csv/Excel from grid placed in RadAjaxPanel

5 posts, 0 answers
  1. Swapnil
    Swapnil avatar
    96 posts
    Member since:
    Aug 2013

    Posted 13 Sep 2013 Link to this post

    hi,
    i am having grid(placed) in  RADAJAXPANEL and i want export to all but when i click to any button for exporting nothing will happen
    How can i do this?
    my Grid is
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
                               <%-- EnableViewState="False" --%>
                               <telerik:RadGrid ID="RadGrid1" runat="server" Width="530px" OnNeedDataSource="RadGrid1_NeedDataSource"
                                   AllowPaging="true" PageSize="10" AllowSorting="true" ShowGroupPanel="True" Skin="Default"
                                   OnDeleteCommand="RadGrid1_DeleteCommand" HeaderStyle-Font-Bold="true" OnPreRender="RadGrid1_PreRender"
                                   OnUpdateCommand="RadGrid1_UpdateCommand" OnItemCreated="RadGrid1_ItemCreated"
                                   OnInsertCommand="RadGrid1_InsertCommand">
                                   <ExportSettings ExportOnlyData="true" OpenInNewWindow="true" IgnorePaging="true">
                                       <Pdf PageHeight="210mm" PageWidth="297mm" DefaultFontFamily="Arial Unicode MS" PageTopMargin="45mm"
                                           BorderStyle="Medium" BorderColor="#666666">
                                       </Pdf>
                                       <Csv />
                                       <Excel />
                                   </ExportSettings>
                                   <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true"></PagerStyle>
                                   <ClientSettings Selecting-AllowRowSelect="true" AllowDragToGroup="True" EnablePostBackOnRowClick="true">
                                       <Selecting AllowRowSelect="True" UseClientSelectColumnOnly="True"></Selecting>
                                   </ClientSettings>
                                   <MasterTableView EditMode="EditForms" AutoGenerateColumns="true" DataKeyNames="CompId"
                                       CommandItemDisplay="Top" CommandItemSettings-ShowAddNewRecordButton="true">
                                       <CommandItemSettings ShowExportToPdfButton="true" />
                                       <CommandItemSettings ShowExportToCsvButton="true" />
                                       <CommandItemSettings ShowExportToExcelButton="true" />
                                       <CommandItemSettings ShowExportToWordButton="true" />
                                       <EditFormSettings FormMainTableStyle-HorizontalAlign="Center" EditColumn-ButtonType="ImageButton"
                                           FormTableStyle-Width="300px" FormTableButtonRowStyle-HorizontalAlign="Center"
                                           FormTableStyle-CellPadding="3" FormMainTableStyle-Font-Bold="true" FormMainTableStyle-ForeColor="Purple"
                                           FormStyle-CssClass="" FormTableStyle-CellSpacing="5" InsertCaption="Add New Record"
                                           FormCaptionStyle-Font-Bold="true" FormCaptionStyle-Font-Underline="true" FormCaptionStyle-ForeColor="Black"
                                           FormCaptionStyle-Font-Size="Large" FormCaptionStyle-HorizontalAlign="Center"
                                           FormCaptionStyle-Width="100%">
                                           <FormStyle Width="100%" BackColor="LightCyan"></FormStyle>
                                       </EditFormSettings>
                                       <Columns>
                                           <telerik:GridEditCommandColumn ButtonType="ImageButton">
                                           </telerik:GridEditCommandColumn>
                                       </Columns>
                                   </MasterTableView>
                                   <MasterTableView>
                                       <Columns>
                                           <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"
                                               ButtonType="ImageButton" />
                                       </Columns>
                                   </MasterTableView>
                               </telerik:RadGrid>
                           </telerik:RadAjaxPanel>

    thanks
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 13 Sep 2013 Link to this post

    Hi Swapnil,

    The exporting feature works only with regular postbacks. This means, that the asynchronous postback should be canceled when performing an export.Please modify the code as shown below.

    ASPX:
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="onRequestStart">
    . . . .
     </telerik:RadAjaxPanel>

    JS:
    <script type="text/javascript">
        function onRequestStart(sender, args) {
            if (args.get_eventTarget().indexOf("ExportTo") >= 0) {
                args.set_enableAjax(false);
            }
        }
    </script>

    Thanks,
    Princy
  3. Swapnil
    Swapnil avatar
    96 posts
    Member since:
    Aug 2013

    Posted 13 Sep 2013 Link to this post

    For now with your code working fine but looking at my code are u feel that is here really i need RadAjaxPanel Should i remove it or Can i ENABLEAJAX true after exporting is done
    like when i want export at that time only my panel gets disabled and at all time it will be enabled

    and another problem is grid exporting records as well as edit and delete text with each record

    Thanks
    Swapnil
  4. Kostadin
    Admin
    Kostadin avatar
    1733 posts

    Posted 17 Sep 2013 Link to this post

    Hi Swapnil,

    The Princy's approach will disable the ajax only when export command is fired and will be enabled it afterwards. A possible solution is to set Exportable property to false to the column which you do not want ot be exported. For instance check out the following code snippet.
    <Columns>
        <telerik:GridEditCommandColumn ButtonType="ImageButton" Exportable="false">
        </telerik:GridEditCommandColumn>
    </Columns>


    Regards,
    Kostadin
    Telerik
    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 the blog feed now.
  5. Omar
    Omar avatar
    2 posts
    Member since:
    Nov 2017

    Posted 11 Nov Link to this post

    I already implemented the solution provided by Princy, but right now i´m still having a hard time. Due to the fact that whenever i export the csv, my current page is lost, i mean, it´s being replaced by a blank page. Here is my code, and this is inside a master page.

    <telerik:RadAjaxPanel ID="pnlManagerCandidates" runat="server" Cssclass="responsivePanel noBorder" Visible="true" ClientEvents-OnRequestStart="onRequestStart">
                <p>This panel shows who has been selected to participate in this program.</p>                  
            <telerik:RadGrid
                ID="grdCandidates"
                runat="server"
                AllowSorting="true"
                AutoGenerateColumns="false"
                OnNeedDataSource="grdCandidates_Fill"    
                OnRowCommand="grdCandidates_RowCommand" 
                OnRowDataBound="grdCandidates_RowDataBound"
                OnItemCommand="grdCandidates_ItemCommand"   
                Font-Names="Roboto"
                Font-Size="Small"
                Font-Bold="false"
                ItemStyle-Font-Names="Roboto"
                ItemStyle-Font-Size="Small"
                ItemStyle-Font-Bold="false"
                AlternatingItemStyle-Font-Names="Roboto"
                AlternatingItemStyle-Font-Size="Small"
                AlternatingItemStyle-Font-Bold="false"
                AlternatingItemStyle-Backcolor="#F5F5F5"
                AllowPaging="True"
                PageSize="500">
                <ExportSettings HideStructureColumns="true" ExportOnlyData="true" OpenInNewWindow="true" FileName="Talent"></ExportSettings>
                <PagerStyle Position="TopAndBottom" /> 
                <MasterTableView DataKeyNames="Id" CommandItemDisplay="Top">
                    <CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" ShowExportToCsvButton="true" />
                    <Columns>
                        <telerik:GridTemplateColumn HeaderStyle-HorizontalAlign="Center" HeaderText="Name" UniqueName="Name" SortExpression="FullName">
                            <ItemTemplate> 
                                <asp:HyperLink  runat="server" Text='<%# Eval("FullName") %>' NavigateUrl='<%# Eval("Email", "mailto:{0}?Subject=Talent") %>'  /> 
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="DifferentiatorTitle" UniqueName="DifferentiatorTitle" HeaderStyle-HorizontalAlign="Center" HeaderText="Differentiator" 
                            ReadOnly="True" SortExpression="DifferentiatorTitle" />
                        <telerik:GridBoundColumn DataField="QuestionnaireName" UniqueName="QuestionnaireName" HeaderStyle-HorizontalAlign="Center"
                            ReadOnly="True" SortExpression="QuestionnaireName"/>
                        <telerik:GridBoundColumn DataField="ReferenceDataTitle" UniqueName="ReferenceDataTitle" HeaderStyle-HorizontalAlign="Center" HeaderText="Ref. Data"
                            ReadOnly="True" SortExpression="ReferenceDataTitle"/>
                        <telerik:GridTemplateColumn HeaderStyle-HorizontalAlign="Center" HeaderText="Status" UniqueName="Status" SortExpression="CandidateStatusDescription">
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("CandidateStatusDescription") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderText="Re-Invite" UniqueName="ReInvite" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50px">
                            <ItemTemplate>
                                <asp:ImageButton runat="server" ToolTip="Re-Invite" Visible="false" CommandArgument='<%# Eval("Id") %>'
                                    CommandName="ReInvite" ImageUrl="../Images/reinvite.png" CausesValidation="false" ID="btnReInvite"></asp:ImageButton>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderText="Report" UniqueName="Report" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50px">
                            <ItemTemplate>
                                <asp:ImageButton runat="server" ToolTip="View report" Visible="false" CommandName="Report"
                                    CommandArgument='<%# Eval("ReportId") + "," + Eval("FirstName") + Eval("LastName") %>'
                                    ID="btnReport" ImageUrl="../Images/print.png"></asp:ImageButton>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderText="Options" UniqueName="Options" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50px">
                            <ItemTemplate>
                                <asp:ImageButton runat="server" ToolTip="Rebuild report with alternative options" Visible="false" CommandArgument='<%# Eval("Id") %>'
                                    CommandName="Rebuild" ImageUrl="../Images/options.png" CausesValidation="false" ID="btnRebuild"></asp:ImageButton>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderText="Develop" UniqueName="Develop" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50px">
                            <ItemTemplate>
                                <asp:ImageButton runat="server" ToolTip="Develop" Visible="false" CommandArgument='<%# Eval("PersonId") %>'
                                    CommandName="Develop" ImageUrl="../Images/develop.png" CausesValidation="false" ID="btnDevelop"></asp:ImageButton>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderText="Reference" UniqueName="Reference" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50px">
                            <ItemTemplate>
                                <asp:ImageButton runat="server" ToolTip="Create reference data" Visible="false"
                                    CommandName="ReferenceData" ImageUrl="../Images/createRefData.png" CausesValidation="false" ID="btnReferenceData" CommandArgument='<%# Eval("Id") %>'
                                    OnClientClick="return confirm('This will create benchmark reference data based on this review.\nDo you want to continue?');"></asp:ImageButton>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderText="Reviews" UniqueName="Reviews" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50px">
                            <ItemTemplate>
                                <asp:ImageButton runat="server" ToolTip="Manage reviews" CommandArgument='<%# Eval("Id") %>'
                                    CommandName="Reviews" ImageUrl="../Images/select.png" CausesValidation="false" ID="btnReview" Visible="false"></asp:ImageButton>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderText="Re-Open" UniqueName="ReOpen" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50px">
                            <ItemTemplate>
                                <asp:ImageButton runat="server" ToolTip="Re-Open" Visible="false" CommandArgument='<%# Eval("Id") %>'
                                    CommandName="UnComplete" ImageUrl="../Images/repeat.png" CausesValidation="false"
                                    ID="btnUnComplete"></asp:ImageButton>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderText="Delete" UniqueName="Delete" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="50px">
                            <ItemTemplate>
                                <asp:ImageButton runat="server" ID="btnDelete" ToolTip="Delete candidate" CommandArgument='<%# Eval("Id") %>'
                                    CommandName="DeleteCandidate" ImageUrl="../Images/delete.png" CausesValidation="false"></asp:ImageButton>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn DataField="Category" HeaderStyle-HorizontalAlign="Center" HeaderText="Category"
                            ReadOnly="True" SortExpression="Category" Display="false"/>
                        <telerik:GridBoundColumn DataField="LoginId" HeaderStyle-HorizontalAlign="Center" HeaderText="LoginId"
                            ReadOnly="True" SortExpression="LoginId" Display="false"/>
                        <telerik:GridBoundColumn DataField="FirstName" HeaderStyle-HorizontalAlign="Center" HeaderText="FirstName"
                            ReadOnly="True" SortExpression="FirstName" Display="false"/>        
                        <telerik:GridBoundColumn DataField="LastName" HeaderStyle-HorizontalAlign="Center" HeaderText="LastName"
                            ReadOnly="True" SortExpression="LastName" Display="false"/>
                        <telerik:GridBoundColumn DataField="Email" HeaderStyle-HorizontalAlign="Center" HeaderText="Email"
                            ReadOnly="True" SortExpression="Email" Display="false"/>
                        <telerik:GridBoundColumn DataField="StaffNo" HeaderStyle-HorizontalAlign="Center" HeaderText="StaffNo"
                            ReadOnly="True" SortExpression="StaffNo" Display="false"/>
                        <telerik:GridBoundColumn DataField="Moderator" HeaderStyle-HorizontalAlign="Center" HeaderText="Moderator/ReviewerGroup"
                            ReadOnly="True" SortExpression="Moderator" Display="false"/>
                        <telerik:GridBoundColumn DataField="Differentiator" HeaderStyle-HorizontalAlign="Center" HeaderText="Differentiator"
                            ReadOnly="True" SortExpression="Differentiator" Display="false"/>              
                    </Columns>
                    </MasterTableView>
                </telerik:RadGrid>
                </telerik:RadAjaxPanel>

    function onRequestStart(sender, args)
    {
        if ((args.EventTarget.indexOf("ExportToCsvButton") >= 0))
        {
            args.set_enableAjax(false);
        }    
    }

     

    Hope you can help me out with this

     

     

Back to Top