There is a bound column in my Razor MVC Grid that I do not want exported to Excel. I have seen some examples that show creating an Excel export event then using hideColumn to remove the column but that does not seem to work for me. How can I hide a column in the grid export to Excel?
.Events(e => e.ExcelExport("excelExport"))
e.sender.hideColumn("Received");
}
4 Answers, 1 is accepted
Hello John,
During ExcelExport event you cannot change the rendering so that to affect the exported content. What you can do with this event is to cancel it and based on predefined flags to export again programmatically and show back the column. You can see the solution here: http://www.telerik.com/forums/export-to-grid-hide-columns#on_CdInsGESYqc5Jumibow.
Or use similar logic like this one:
function
excelExport(e) {
if
(e.sender._exporting === undefined) {
e.sender._exporting =
true
;
}
if
(e.sender._exporting) {
e.sender.hideColumn(
"Received"
);
e.preventDefault();
setTimeout(
function
() {
e.sender._exporting =
false
;
e.sender.saveAsExcel();
});
}
else
{
e.sender._exporting =
true
;
e.sender.showColumn(
"Received"
);
}
}
Regards,
Ianko
Telerik by Progress
Hello John,
This is an expected behavior as the inner table is being programmatically set up with different width.
If you need to retain the 100% width behavior you can use the following line of code after calling hideColumn method.
e.sender.table.css("width", "");
Regards,Ianko
Telerik by Progress
In my case it worked when I put it after the hideColumn and showColumn. Thanks for the help!