I'm trying to export a grid to Excel, and I have followed the Telerik example:
https://demos.telerik.com/aspnet-mvc/grid/excel-export?autoRun=true&theme=default-main
But what I cannot manage to do is to prevent a call to excel_export_read when clicking the Export to Excel button. In Chrome Devtools I can see that also the official Telerik example calls this method a second time when clicking, but I was under the impression that the component would try to create the excel file client side. Is this not possible?
Here is my code:
@(Html.Kendo().Grid<CampaignSimulationResult>()
.Name("SimulateResult")
.ToolBar(tools => tools.Excel())
.DefaultSettings()
.Columns(column =>
{
column.Bound(m => m.Region).HeaderHtmlAttributes(new { style = "text-align:center" })
.HtmlAttributes(new { style = "text-align: center" });
column.Bound(m => m.ParameterID).Format("{0:##,#}").HtmlAttributes(new { style = "text-align: right" }).HeaderHtmlAttributes(new { style = "text-align:center" });
column.Bound(m => m.Parameter).HtmlAttributes(new { style = "white-space: nowrap;" }).HeaderHtmlAttributes(new { style = "text-align:center" });
}
).Excel(excel => excel
.FileName("Kendo UI Grid Export.xlsx")
.Filterable(true)
)
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("ExcelExportRead", "Campaign", new RouteValueDictionary { { "area", "Admin" } }))
)
)
I figured this out. I had to add ServerOperation(false) to the DataSource:
.DataSource(dataSource => dataSource .Ajax() .Read(read => read.Action("ExcelExportRead", "Campaign", new RouteValueDictionary { { "area", "Admin" } })) .ServerOperation(false)