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

Using ClientEvents.OnCommand and exporting

7 Answers 118 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JP
Top achievements
Rank 1
JP asked on 05 Sep 2012, 01:57 PM
Hi,

when I'm using ClientSettings.ClientEvents.OnCommand, the exporting doesn't work anymore. My grid displays all 4 export buttons (pdf, excel, word, csv) which work fine when I don't use the OnCommand function.

Even if the function body is empty, the exporting doesn't work. But as soon as I remove the ClientSettings.ClientEvents.
OnCommand handler, everything works fine again. How can I use OnCommand and keep the exporting working?

Thanks!

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Sep 2012, 04:30 AM
Hi,

Unfortunately I cannot replicate the issue at my end. The exporting is working as expected on attaching the OnCommand event. Here is the sample code.
aspx:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource2" AutoGenerateColumns="false">
 <ExportSettings ExportOnlyData="true" Excel-Format="Html"></ExportSettings>
 <MasterTableView CommandItemDisplay="top" DataKeyNames="EmployeeID">
   <CommandItemSettings ShowExportToExcelButton="true" />
    <Columns>
      <telerik:GridBoundColumn   DataField="EmployeeID" UniqueName="EmployeeID" HeaderText="EmployeeID"></telerik:GridBoundColumn>
      <telerik:GridBoundColumn DataField="LastName" UniqueName="LastName" HeaderText="LastName"></telerik:GridBoundColumn>
    </Columns>
 </MasterTableView>
 <ClientSettings >
    <ClientEvents  OnCommand="OnCommand" />
 </ClientSettings>
</telerik:RadGrid>
JS:
<script type="text/javascript">
    function OnCommand(sender, args) {
        alert(args.get_commandName());
    }
</script>

Thanks,
Shinu.
0
Kristian
Top achievements
Rank 1
answered on 27 Nov 2012, 10:22 AM
I'm having the same problem.  The example provided didn't replicate the issue as it was missing a few pieces of the puzzle.  To replicate the issue, include a RadAjaxmanager and use this to Ajaxify a Radgrid.  As the Export functions need to postback, add an onRequestStart method to RadAjaxManager to disable ajax methods on the export buttons:

function onRequestStart(sender, args) {
    if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
        args.get_eventTarget().indexOf("â—¦ExportToPdfButton") >= 0 ||
        args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||
        args.get_eventTarget().indexOf("ExportToCsvButton")) {
        args.set_enableAjax(false);
    }
}

This works nicely and the RadGrid functions (eg. Paging, Sorting) are all Ajaxed, and the Export functions postback, and work as expected.  Now add an OnCommand client event to the RadGrid.  This breaks the Export functions.

The problem occurring is that when the OnCommand event is added to the RadGrid, the eventTarget passed into the OnRequestStart method will now always be the name of the Grid instead of the name of the button or control clicked.  As a result the enableAjax won't be triggered as you can't catch or check for the button that triggered the request.  As a result Exporting will no longer work.

Seems like you can't have an AJAX grid + OnCommand method + Export Working together.  You can only get two of these features working at a time.  Am I missing something or is this an issue?

Thanks
0
Antonio Stoilkov
Telerik team
answered on 30 Nov 2012, 11:12 AM
Hello Kristian,

The experienced behavior is caused from the implementation of the OnCommand method. In order to resolve your issue you could check the args.get_eventArgument() function which will return the CommandArgument of the clicked item and filter depending on that value.

Additionally, I have informed the developers so they could further investigate the problem.

All the best,
Antonio Stoilkov
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
Darwin
Top achievements
Rank 1
answered on 18 Apr 2013, 10:10 PM
I just ran into the very same problem.

Our Export button was working just fine.  Then I needed to turn on the the loading indicator for a grid without actually rebinding the grid while I performed some other action.  To do this, I followed an example I found on the Telerik web site.  Essentially, I added the following:

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            var currentLoadingPanel = null;
            var currentUpdatedControl = null;
            function RequestStart(sender, args) {
                currentLoadingPanel = $find("<%= RadAjaxLoadingPanel1.ClientID%>");

                if (args.get_eventTarget() == "<%= SelectAllOpenRequestsBtn.UniqueID %>") {

                    currentUpdatedControl = "<%= rgRequests.ClientID %>";
                    //show the loading panel over the updated control  
                    currentLoadingPanel.show(currentUpdatedControl);
                }
                if (args.get_eventTarget() == "<%= SelectAllPendingRequestsBtn.UniqueID %>") {
                    currentUpdatedControl = "<%= rgPending.ClientID %>";
                    //show the loading panel over the updated control  
                    currentLoadingPanel.show(currentUpdatedControl);
                }
            }
            function ResponseEnd() {
                //hide the loading panel and clean up the global variables              
                if (currentLoadingPanel != null) {
                    currentLoadingPanel.hide(currentUpdatedControl);
                }
                currentUpdatedControl = null;
                currentLoadingPanel = null;
            }  
        </script>
    </telerik:RadCodeBlock>

.....

<ClientEvents OnRequestStart="RequestStart" OnResponseEnd="ResponseEnd"></ClientEvents>


That caused the Export to stop working and, when the Export button was clicked, it caused all the cells in the grid to become equal in size and the grid headers disappeared.  I sure would like to turn on the loading indicators.  We are currently using version 2012.2.724.40.  We tried recently to upgrade to version 2013.1.220.40 but that caused us enough problems we had to revert.  Is there a way to fix this problem in the version we are currently using?

Addendum:  I upgraded to version 2013.1.220.40 again, just to see if it would solve this one problem for me.  It did not.
0
Antonio Stoilkov
Telerik team
answered on 23 Apr 2013, 07:05 AM
Hi Darwin,

In order for the Export to work you need to cancel the ajax when an export button is clicked as shown in the example below.
function RequestStart(sender, args)
{
    currentLoadingPanel = $find("<%= RadAjaxLoadingPanel1.ClientID%>");
 
    if (args.get_eventTarget().indexOf("Button1") >= 0)
    {
        args.set_enableAjax(false);
    }
    else if (args.get_eventTarget().indexOf("ExportToExcelButton") >= 0 ||
            args.get_eventTarget().indexOf("ExportToWordButton") >= 0 ||
            args.get_eventTarget().indexOf("ExportToPdfButton") >= 0)
    {
        args.set_enableAjax(false);
    }
    else if (args.get_eventTarget() == "<%= SelectAllOpenRequestsBtn.UniqueID %>")
    {
 
        currentUpdatedControl = "<%= rgRequests.ClientID %>";
        //show the loading panel over the updated control 
        currentLoadingPanel.show(currentUpdatedControl);
    }
    else if (args.get_eventTarget() == "<%= SelectAllPendingRequestsBtn.UniqueID %>")
    {
        currentUpdatedControl = "<%= rgPending.ClientID %>";
        //show the loading panel over the updated control 
        currentLoadingPanel.show(currentUpdatedControl);
    }
}

If your issue still persists you could open a formal ticket attaching a sample project showing the unwanted behavior so we could debug it and advice you with the best possible approach.

Kind regards,
Antonio Stoilkov
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
Lenny_shp
Top achievements
Rank 2
answered on 02 Oct 2015, 02:28 PM

This issue still exists in 2015.2.908.45.

AjaxManager onRequestStart defined.

RadGrid OnCommand used (culprit).

Built-in Excel Export button does not work because it cannot determine when the button is clicked.  RadGrid1 is passed instead.

Can you describe how to use args.get_eventArgument() to determine when Export button is clicked so args.set_enableAjax(false); can be set ?

0
Eyup
Telerik team
answered on 07 Oct 2015, 12:10 PM
Hello Lenny,

I am sending a sample RadGrid web site to demonstrate that the approach should work as expected:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/ajaxified-radgrid/what-you-should-have-in-mind/export-from-ajaxified-grid

Please run the attached application and let me know about the result on your side.

Regards,
Eyup
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
Tags
Grid
Asked by
JP
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Kristian
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Darwin
Top achievements
Rank 1
Lenny_shp
Top achievements
Rank 2
Eyup
Telerik team
Share this question
or