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

export to Excel...

7 Answers 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mark baer
Top achievements
Rank 1
mark baer asked on 07 Feb 2013, 05:02 PM
I am trying to use the Export to Excel functionality on the RadGrid and I can not get it to work.  My Telerik controls are about 1 year old...I am not able to upgrade currently because our two legal departments are arguing over Eula crap.  Can anybody help me out?  Basically, when I hit the Export to Excel button, the grid refreshes(ajax), but nothing happens.  I have included my HTML below.  The version of my Telerik Controls are:  2012.1.411.40

ASP.NET 4.0, Windows 7

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" OnGridExporting="RadGrid1_GridExporting" ShowGroupPanel="true" OnNeedDataSource="RadGrid1_NeedDataSource" ItemStyle-Font-Size="Small" HeaderStyle-HorizontalAlign="Center" CellSpacing="0" PageSize="500" Height="500px" Width="1250" GridLines="None" Skin="WebBlue" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True"><br>        <ClientSettings AllowDragToGroup="True"><br>            <Scrolling AllowScroll="True" UseStaticHeaders="True" /><br><br>        </ClientSettings><br>        <ExportSettings ExportOnlyData="true" OpenInNewWindow="true"><br>        </ExportSettings><br>        <GroupingSettings ShowUnGroupButton="true" CaseSensitive="false"></GroupingSettings><br>        <MasterTableView Font-Size="Small" CommandItemDisplay="Top"><br>            <br>           <CommandItemSettings ShowExportToExcelButton="true"></CommandItemSettings><br>           <GroupByExpressions><br> <br>              <telerik:GridGroupByExpression><br>                <SelectFields><br>                  <telerik:GridGroupByField FieldName="InvoiceNumber" HeaderText="Invoice Number" /><br>                </SelectFields><br>                <GroupByFields><br>                  <telerik:GridGroupByField FieldName="InvoiceNumber" SortOrder="Ascending" /><br>                </GroupByFields><br>              </telerik:GridGroupByExpression><br> <br>            </GroupByExpressions><br>            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings><br>            <ItemStyle Font-Size="X-Small" /><br>            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"><br>                <HeaderStyle Width="20px"></HeaderStyle><br>            </RowIndicatorColumn><br><br>            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"><br>                <HeaderStyle Width="20px"></HeaderStyle><br>            </ExpandCollapseColumn><br><br>            <Columns> <br>                <telerik:GridBoundColumn FilterControlAltText="Filter column2 column" ItemStyle-Width="90" ItemStyle-Font-Size="Small" HeaderStyle-Width="90" UniqueName="column2" FilterControlWidth="50" DataField="InvoiceNumber" ItemStyle-HorizontalAlign="Center" HeaderText="Invoice #"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column column" ItemStyle-Width="60" Visible="false" ItemStyle-Font-Size="Small" HeaderStyle-Width="60" UniqueName="column" FilterControlWidth="40" DataField="RecordType" HeaderText="Rec Type"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column1 column" ItemStyle-Width="75" ItemStyle-Font-Size="Small" HeaderStyle-Width="75" UniqueName="column1" AllowFiltering="false" DataField="PostDate" HeaderText="Post Date"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column3 column" ItemStyle-Width="40" ItemStyle-Font-Size="Small" HeaderStyle-Width="40" UniqueName="column3" ItemStyle-HorizontalAlign="Center" AllowFiltering="false" DataField="Sign" HeaderText="Sign"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column4 column" ItemStyle-Width="85" ItemStyle-Font-Size="Small" HeaderStyle-Width="85" UniqueName="column4" FilterControlWidth="40" ItemStyle-HorizontalAlign="Center" DataFormatString="" DataField="Amount" HeaderText="Amount"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column5 column" ItemStyle-Width="40" ItemStyle-Font-Size="Small" HeaderStyle-Width="40" AllowFiltering="false" UniqueName="column5" ItemStyle-HorizontalAlign="Center" DataField="Currency" HeaderText="Cur"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column6 column" ItemStyle-Width="40" ItemStyle-Font-Size="Small" HeaderStyle-Width="40" AllowFiltering="false" UniqueName="column6" DataField="Geo" HeaderText="Geo"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column7 column" ItemStyle-Width="50" ItemStyle-Font-Size="Small" HeaderStyle-Width="50" AllowFiltering="false" UniqueName="column7" DataField="UOM" ItemStyle-HorizontalAlign="Center" HeaderText="UOM"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column8 column" ItemStyle-Width="80" ItemStyle-Font-Size="Small" HeaderStyle-Width="80" AllowFiltering="false" UniqueName="column8" DataField="GLAcct" ItemStyle-HorizontalAlign="Center" HeaderText="GL Acct"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column9 column" ItemStyle-Width="55" ItemStyle-Font-Size="Small" HeaderStyle-Width="55" AllowFiltering="false" UniqueName="column9" DataField="APRef" HeaderText="AP Ref"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column10 column" ItemStyle-Width="70" ItemStyle-Font-Size="Small" HeaderStyle-Width="70" ItemStyle-HorizontalAlign="Center" UniqueName="column10" FilterControlWidth="25" DataField="CustRef" HeaderText="Cust Ref"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column11 column" ItemStyle-Width="70" ItemStyle-Font-Size="Small" HeaderStyle-Width="70" ItemStyle-HorizontalAlign="Center" UniqueName="column11" FilterControlWidth="30" DataField="SrcCo" HeaderText="Src Co"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column12 column" ItemStyle-Width="70" ItemStyle-Font-Size="Small" HeaderStyle-Width="70" ItemStyle-HorizontalAlign="Center" UniqueName="column12" FilterControlWidth="30" DataField="ChgCo" HeaderText="Chg Co"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column13 column" ItemStyle-Width="70" ItemStyle-Font-Size="Small" HeaderStyle-Width="70" ItemStyle-HorizontalAlign="Center" UniqueName="column13" FilterControlWidth="25" DataField="BusArea" HeaderText="Bus Area"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column14 column" ItemStyle-Width="90" ItemStyle-Font-Size="Small" HeaderStyle-Width="90" UniqueName="column14" FilterControlWidth="50" DataField="CostCenter" ItemStyle-HorizontalAlign="Center" HeaderText="Cost Ctr"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column15 column" ItemStyle-Width="85" ItemStyle-Font-Size="Small" HeaderStyle-Width="85" UniqueName="column15" FilterControlWidth="45" DataField="ProfitCenter" HeaderText="Profit Ctr"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column16 column" ItemStyle-Width="85" ItemStyle-Font-Size="Small" HeaderStyle-Width="85" UniqueName="column16" FilterControlWidth="45" DataField="Order" HeaderText="Order"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column17 column" ItemStyle-Width="115" ItemStyle-Font-Size="Small" HeaderStyle-Width="115" UniqueName="column17" FilterControlWidth="70" DataField="WBSElement" HeaderText="WBS Element"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column18 column" ItemStyle-Width="85" ItemStyle-Font-Size="Small" HeaderStyle-Width="85" UniqueName="column18" FilterControlWidth="45" DataField="MPMIssue" HeaderText="MPM Issue"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn FilterControlAltText="Filter column19 column" ItemStyle-Width="70" ItemStyle-Font-Size="Small" HeaderStyle-Width="70" UniqueName="column19" Visible="false" DataField="TrdPartner" HeaderText="Trd Partner"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn DataField="TPBusinessArea" FilterControlAltText="Filter column20 column" ItemStyle-Font-Size="Small" ItemStyle-Width="70" HeaderStyle-Width="70" Visible="false" HeaderText="TP Busn Area" UniqueName="column20"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn DataField="DistChannel" FilterControlAltText="Filter column21 column" ItemStyle-Font-Size="Small" ItemStyle-Width="90" HeaderStyle-Width="90" FilterControlWidth="50" HeaderText="Dist Channel" UniqueName="column21"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn DataField="Material" FilterControlAltText="Filter column22 column" ItemStyle-Font-Size="Small" ItemStyle-Width="85" HeaderStyle-Width="85" FilterControlWidth="45" HeaderText="Material" UniqueName="column22"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn DataField="Description" FilterControlAltText="Filter column23 column" ItemStyle-Font-Size="Small" ItemStyle-Width="160" AllowFiltering="true" FilterControlWidth="120" HeaderStyle-Width="160" HeaderText="Description" UniqueName="column23"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn DataField="Quantity" FilterControlAltText="Filter column24 column" ItemStyle-Font-Size="Small" ItemStyle-Width="65" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="65" AllowFiltering="false" HeaderText="Quantity" UniqueName="column24"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn DataField="TaxCode" FilterControlAltText="Filter column25 column" ItemStyle-Font-Size="Small" ItemStyle-Width="55" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="55" AllowFiltering="false" HeaderText="Tax Code" UniqueName="column25"><br>                </telerik:GridBoundColumn><br>                <telerik:GridBoundColumn DataField="Attrib1" FilterControlAltText="Filter column26 column" ItemStyle-Font-Size="Small" ItemStyle-Width="50" HeaderStyle-Width="50" HeaderText="Attrib 1" Visible="false" UniqueName="column26"><br>                </telerik:GridBoundColumn><br>            </Columns><br><br>            <EditFormSettings><br>                <EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn><br>            </EditFormSettings><br>        </MasterTableView><br><br>        <FilterMenu EnableImageSprites="False"></FilterMenu><br>    </telerik:RadGrid>

protected void RadGrid1_GridExporting(object sender, Telerik.Web.UI.GridExportingArgs e)
{
       RadGrid1.ExportSettings.OpenInNewWindow = true;
       RadGrid1.MasterTableView.ExportToExcel();
}

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 08 Feb 2013, 09:59 AM
Hi,

The exporting feature of the control work with regular postbacks only. If you have ajaxified the grid, make sure that it is disabled before exporting.
JS:
function onRequestStart(sender, args) {
  if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0)
    args.set_enableAjax(false);
}

Thanks,
Shinu
0
mark baer
Top achievements
Rank 1
answered on 11 Feb 2013, 09:55 PM
I tried adding that code to the page, but it never entered that event/function...Do I have to wire it up somehow?

thanks
0
Shinu
Top achievements
Rank 1
answered on 12 Feb 2013, 04:50 AM
Hi,

You can attach the event as shown below.
aspx:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" ClientEvents-OnRequestStart="onRequestStart">
   <AjaxSettings>
       <telerik:AjaxSetting AjaxControlID="RadGrid1">
          <UpdatedControls>
              <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
          </UpdatedControls>
       </telerik:AjaxSetting>
   </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource2" AutoGenerateColumns="false">
    <MasterTableView CommandItemDisplay="Top">
       <CommandItemSettings ShowExportToExcelButton="true" />
         <Columns>
           <telerik:GridBoundColumn DataField="ShippedDate" UniqueName="ShippedDate"></telerik:GridBoundColumn>
           <telerik:GridBoundColumn DataField="OrderID" UniqueName="OrderID"></telerik:GridBoundColumn>
         </Columns>
    </MasterTableView>
</telerik:RadGrid>

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

Thanks,
Shinu
0
mark baer
Top achievements
Rank 1
answered on 14 Feb 2013, 06:50 PM
Okay, I tried that and my page blows up.  The main difference between my code and yours is that my "Ajax Manager" is on my MasterPage and I have an Ajax Manager Proxy on my child page that has the RadGrid pointing to itself...Not sure if that matters or not.  So...I had to put the

ClientEvents-OnRequestStart="onRequestStart"
On the masterpage because there is no such property on the "Proxy".

thanks

mark

0
Kostadin
Telerik team
answered on 19 Feb 2013, 02:38 PM
Hi Mark,

I prepared a small sample based on your scenario. Give it a try and let me know about the result.

All the best,
Kostadin
the Telerik team
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 their blog feed now.
0
mark baer
Top achievements
Rank 1
answered on 20 Feb 2013, 09:39 PM
Thank you very much.  That sample helped tremendously...Only one more question.  If I have pagesize=500, but there are 1500 items in the "Datatable", it only exports the 500 showing...Is there a way to be able to export all 1500 records?

Thanks again.
0
Shinu
Top achievements
Rank 1
answered on 21 Feb 2013, 05:43 AM
Hi Mark,

Please set the 'IgnorePaging' property of export setting as true to achieve this.

ASPX:
<telerik:RadGrid ID="RadGrid1" . .  .  .  . .  .  .
          <ExportSettings ExportOnlyData="true" IgnorePaging="true">
          </ExportSettings>

Thanks,
Shinu.
Tags
Grid
Asked by
mark baer
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
mark baer
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or