Bug Report T582403
Visible to All Users

GridView - The BeforeExport event is not raised on exporting data using GridViewToolbarCommand

created 7 years ago

I noticed in your enhancements list for 17.2 the new built-in functionality for exporting gridview data.  I was able to follow the provided demo to create a grid that could export to Excel using the GridViewToolbarCommand object.  I really like that I don't need to pass the grid settings back from a controller method so I can call them from a Export controller action.  I can keep my grid settings in the callback view like I do elsewhere.

However, I want to display additional columns when exporting to Excel.  I found Q460085 which described using the BeforeExport  event to customize column display like follows:

C#
settings.SettingsExport.BeforeExport = (sender, e) => { MVCxGridView gridView = sender as MVCxGridView; if (sender == null) return; gridView.Columns["Text"].Visible =!isExport; };

But when I added this to my grid settings, the event never appears to fire.  Should this work with an export invoked by the GridViewToolbarCommand?  How can I figure out in my grid settings when I'm displaying the grid on the screen and when I'm exporting it?

Comments (2)
Vova (DevExpress Support) 7 years ago

    Hello Jeff,

    We need more time to research this scenario. Your patience is highly appreciated.

    Regards,
    Vova

    DevExpress Support Team 7 years ago

      Hello,

      I've reproduced this issue and forwarded it to our developers for further investigation. We will update this report once any news regarding this subject is available.

      In the meantime, you can use the ToolbarItemClick event instead of the BeforeExport event, as shown below:

      C#
      settings.ToolbarItemClick += (s, e) => { var gridView = s as MVCxGridView; if(gridView == null) return; if(e.Item.Command == GridViewToolbarCommand.ExportToXlsx) { gridView.Columns["Text"].Visible = false; } };

      Answers approved by DevExpress Support

      created 7 years ago

      We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

      Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.