Using ClientEvents.OnCommand and exporting

8 posts, 0 answers
  1. JP
    JP avatar
    120 posts
    Member since:
    Aug 2011

    Posted 05 Sep 2012 Link to this post

    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!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Sep 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kristian
    Kristian avatar
    1 posts
    Member since:
    Nov 2012

    Posted 27 Nov 2012 Link to this post

    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
  5. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 30 Nov 2012 Link to this post

    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.
  6. Darwin
    Darwin avatar
    9 posts
    Member since:
    Jan 2013

    Posted 18 Apr 2013 Link to this post

    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.
  7. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 23 Apr 2013 Link to this post

    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.
  8. Lenny_shp
    Lenny_shp avatar
    343 posts
    Member since:
    Jul 2006

    Posted 02 Oct 2015 in reply to Antonio Stoilkov Link to this post

    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 ?

  9. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 07 Oct 2015 Link to this post

    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
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017