1 Answer, 1 is accepted
Please refer to the following thread, which discusses the reverse scenario - how to hide a column during export. The algorithm in your case will be practically the same.
http://www.telerik.com/forums/export-to-grid-hide-columns
Regards,
Dimo
Telerik
hello Dimo .
I have one hidden column in grid .I want to show this column in excel export and hide one no hidden column .here is my code.
@(Html.Kendo().Grid<CRSWebApp.Models.AuditReportModel>()
.Name("gridAuditReport")
.Columns(columns =>
{
columns.Bound(p => p.CRSReportAuditKey).Title("ID").HtmlAttributes(new { @class = "grid-column-yellow" });
columns.Bound(p => p.ADUserName).Title("User").HtmlAttributes(new { @class = "grid-column-yellow" });
columns.Bound(p => p.ReportName).Title("Report Name").HtmlAttributes(new { @class = "grid-column-yellow" });
columns.Bound(p => p.SearchCriteria).Title("Search Criteria").Width("40%").HtmlAttributes(new { @class = "grid-column-yellow" });
columns.Bound(p => p.ReportStartDate).Title("Start Date").Format("{0:MM/dd/yyyy H:mm:ss}").Hidden(true);
columns.Bound(p => p.ReportStartDateTime).Title("Start Date").ClientTemplate("#=kendo.toString(ReportStartDate,'g')#")
.Format("{0:MM/dd/yyyy H:mm:ss}").HtmlAttributes(new { @class = "grid-column-yellow" });
})
.ToolBar(tools => tools.Excel().HtmlAttributes(new { style = "float:left;" }))
.Pageable(e => e.Refresh(true).PageSizes(true).ButtonCount(5))
.Sortable()
.Filterable(ftb => ftb.Mode(GridFilterMode.Menu)
.Operators(o => o.ForString(s => s
.Clear()
.Contains("Contains")
.IsEqualTo("Is equal to")
.IsNotEqualTo("Is not equal to")
.StartsWith("Starts with")
.EndsWith("Ends with")
)))
.Scrollable(s => s.Height("auto"))
.Resizable(resize => resize.Columns(true))
.Excel(excel => excel
.FileName("BIReport.xlsx")
.AllPages(true)
.Filterable(true)
.ProxyURL(Url.Action("Excel_Export_Save", "Admin"))
)
.Reorderable(a => a.Columns(true))
.Mobile(MobileMode.Auto)
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Single)
.Type(GridSelectionType.Cell))
.Events(e => e.DataBound("onAuditReportRowBound").ExcelExport("ExcelExportEvent"))// .ColumnResize("adjustLastColumn"))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.ServerOperation(true)
.Read(read => read.Action("GetGridAuditReports", "Admin")
.Data("getAdditionalData('" + Model.AuditReportStartDate + "','"
+ Model.AuditReportEndDate + "')")))
)
and
function ExcelExportEvent(e) {
e.sender.showColumn("ReportStartDate");
e.sender.hideColumn("ReportStartDateTime");
}
but it is not working in excel export.
You don't seem to have implemented any of my suggestions in the linked forum thread above.
Regards,
Dimo
Telerik
Hello,
I did it .i have seen your solution ...I was doing some mistake . Thnaks for your reply.