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?
Hello Jeff,
We need more time to research this scenario. Your patience is highly appreciated.
Regards,
Vova
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:
settings.ToolbarItemClick += (s, e) => { var gridView = s as MVCxGridView; if(gridView == null) return; if(e.Item.Command == GridViewToolbarCommand.ExportToXlsx) { gridView.Columns["Text"].Visible = false; } };