Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RadGrid telerik problems with export to excel

I added folowing line to my MasterTableView:

<CommandItemSettings ShowExportToWordButton="true" ShowExportToExcelButton="true" ShowExportToCsvButton="true" />

But when I click on that, loading div appears and then data on the grid is refreshed and nothing else happens. There is no "save file" window.

Am I missing anything ?

like image 837
gruber Avatar asked Jan 17 '12 07:01

gruber


1 Answers

Add the below code before the Grid:

<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>

    <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>

For the code behind add the below one:

protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName ||
            e.CommandName == Telerik.Web.UI.RadGrid.ExportToWordCommandName ||
            e.CommandName == Telerik.Web.UI.RadGrid.ExportToPdfCommandName ||
            e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName)
    {
        gridResult.ExportSettings.IgnorePaging = true;
        gridResult.ExportSettings.OpenInNewWindow = true;
        if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToExcelCommandName)
            gridResult.MasterTableView.ExportToExcel();
        else if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToWordCommandName)
            gridResult.MasterTableView.ExportToWord();
        else if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToCsvCommandName)
            gridResult.MasterTableView.ExportToCSV();
        else if (e.CommandName == Telerik.Web.UI.RadGrid.ExportToPdfCommandName)
            gridResult.MasterTableView.ExportToPdf();

    }
}

reference: http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/exporting/defaultcs.aspx

like image 52
Niran Avatar answered Oct 28 '22 03:10

Niran