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

Making standard postback for exporting RadGrid with AjaxManager

6 Answers 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tushar
Top achievements
Rank 1
Tushar asked on 30 May 2014, 03:06 PM
Hi,
I have implemented custom export functionality to export RadGrid data.
I have added a menu “Export All Columns” to HeaderContextMenu of Grid, which when clicked Grid data should be exported to CSV.

RadGrid is ajaxified using RadAjaxManager:
    <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
            <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="PanelVendor" />
                    <telerik:AjaxUpdatedControl ControlID="pnlGrid" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="RadWindowManager1" />
            </UpdatedControls>
        </telerik:AjaxSetting>        <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="UsersGrid">
            <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="UsersGrid" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

Following this link http://www.telerik.com/support/code-library/export-radgrid-content-to-excel-word-csv-pdf-with-ajax-enabled , I have added javascript code to disable ajax and make standard postback:
function onRadAjaxRequestStart(ajaxManager, eventArgs) {
    if (eventArgs.EventTargetElement.value != undefined && eventArgs.EventTargetElement.value.indexOf("Export") != -1) {
        eventArgs.set_enableAjax(false);
        ajaxManager.set_enableAJAX(false);
    }
}

Now this all works fine and data is exported to CSV when “Export All Columns” header menu is clicked.
But the RadAjaxLoadingPanel is displayed on the grid and it does not go away even after CSV is downloaded.

What do I need to do so that RadAjaxLoadingPanel does not appear while exporting?

6 Answers, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 04 Jun 2014, 10:21 AM
Hi Tushar,

The Code-Library that you are referring to is a rather old and I strongly recommend that you take a look at the following help article, where detailed information for exporting from AJAX enabled RadGrid is available:
Furthermore, for your convenience, following is a very simple example demonstrating how to implement the approach from the help article:
<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" DefaultLoadingPanelID="LoadingPanel1">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
    <ClientEvents OnRequestStart="onRadAjaxRequestStart" />
</telerik:RadAjaxManager>
 
<telerik:RadAjaxLoadingPanel runat="server" Skin="Default" ID="LoadingPanel1"></telerik:RadAjaxLoadingPanel>
 
<telerik:RadCodeBlock runat="server">
    <script type="text/javascript">
        function onRadAjaxRequestStart(sender, args) {
            if (args.get_eventTarget().indexOf("ExportTo") >= 0)
                args.set_enableAjax(false);
        }
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView CommandItemDisplay="Top" CommandItemSettings-ShowExportToCsvButton="true"></MasterTableView>
</telerik:RadGrid>

Finally, please inspect your page for any JavaScript errors when you try to export from the grid, which could prevent the proper work of the controls.

I hope this helps.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Lenny_shp
Top achievements
Rank 2
answered on 01 Oct 2015, 08:03 PM

2015.2.908.45  RadGrid MasterTableView CommandItemSettings-ShowExportToExcelButton="true"

args.get_eventTarget() returns "RadGrid1" when Export button is clicked and not any "ExportTo" button.

No difference with RadCodeBlock or RadScriptBlock.
0
Lenny_shp
Top achievements
Rank 2
answered on 01 Oct 2015, 08:10 PM

I found that RadGrid1's ClientSetting OnCommand="CheckChanges" was preventing the ExportToExcelButton to be reflected in args.get_eventTarget.

Researching...

0
Lenny_shp
Top achievements
Rank 2
answered on 01 Oct 2015, 09:29 PM

Same issue applies to RadAjaxPanel.   I saw some people having the same issue and don't see any resolution for this with the built-in Export Command when RadGrid OnCommand is used, args.get_eventTarget in OnRequestStart has "RadGrid1" instead of "ExportToExcel" button.

 Do we have to use external button outside of the grid to do the export??

0
Konstantin Dikov
Telerik team
answered on 06 Oct 2015, 07:35 AM
Hi,

When you attach handler to the client-side OnCommand event of the grid, the commands mechanism will be changed and the postback will be initiated from the RadGrid. In order to handle that scenario you need to use global variable to determine if an Export command was fired:
<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1" DefaultLoadingPanelID="LoadingPanel1">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadGrid1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
    <ClientEvents OnRequestStart="onRadAjaxRequestStart" />
</telerik:RadAjaxManager>
 
<telerik:RadAjaxLoadingPanel runat="server" Skin="Default" ID="LoadingPanel1"></telerik:RadAjaxLoadingPanel>
 
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        var enableAjax = true;
 
        function onRadAjaxRequestStart(sender, args) {
            args.set_enableAjax(enableAjax);
            enableAjax = true;
        }
 
        function CheckChanges(sender, args) {
            if (args.get_commandName().indexOf("Export") >= 0) {
                enableAjax = false;
            }
        }
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource">
    <MasterTableView CommandItemDisplay="Top" CommandItemSettings-ShowExportToCsvButton="true"></MasterTableView>
    <ClientSettings>
        <ClientEvents OnCommand="CheckChanges" />
    </ClientSettings>
</telerik:RadGrid>

Hope this helps.


Regards,
Konstantin Dikov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Lenny_shp
Top achievements
Rank 2
answered on 07 Oct 2015, 05:19 PM

Konstantin,

Using a global variable worked, thank you!

Tags
Grid
Asked by
Tushar
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Lenny_shp
Top achievements
Rank 2
Share this question
or