Reputation: 924
I have a kendo mvc grid and I am trying to export data to excel.
This is my .chhtml.
<div class="panel-body table-responsive">
@{
var gridBuilder = CodeTaskKendoGrid.CreateTaskGrid(Model.TaskOverviewList, Model.ViewableExtraFields, this.Html, Model.Configuration);
gridBuilder.ToolBar(tools => tools.Excel())
.Excel(excel => excel
.AllPages(true)
.ProxyURL(Url.Action("Excel_Export_Save", "Task"))
);
}
@gridBuilder.ClientDetailTemplateId("client-template")
</div>
<script id="client-template" type="text/x-kendo-template">
# if (SubTasks != null && SubTasks.length > 0) { #
<text>
<table class="adra-kendo-table">
# var j = SubTasks.length; #
# for(var i = 0; i < j; i++) { #
# var ownerName= SubTasks[i].OwnerName; #
# var taskStatusId= SubTasks[i].TaskStatusId; #
# var taskId = SubTasks[i].Id; #
# var periodId = SubTasks[i].PeriodId; #
# var teamId = SubTasks[i].TeamId; #
<tr>
<td>#: SubTasks[i].Id #</td>
<td>#: SubTasks[i].Name #</td>
<td class="# @CodeTaskKendoGrid.OwnerClass("ownerName") #"># @CodeTaskKendoGrid.OwnerName("ownerName") #</td>
<td>#: SubTasks[i].TaskStatus #</td>
<td>#: SubTasks[i].ApprovalStatus #</td>
<td><a class="btn btn-warning btn-xs" href="/Task/EditTask?taskId=#=taskId#&periodId=#=periodId#&teamId=#=teamId#" type="button">Edit</a></td>
</tr>
# } #
</table>
</text>
# } #
And this is where I generate the grid (this is another .cshtml file and I am using this to generate t the grid. I call the method in this file from the above file)
public static GridBuilder<DtoTaskExtended> CreateTaskGrid(IEnumerable<DtoTaskExtended> taskList, IEnumerable<DtoExtraField> viewableExtraFields , System.Web.Mvc.HtmlHelper htmlHelper, TaskGridConfig gridConfig)
{
ExtraFieldConfigs = viewableExtraFields;
Helper = htmlHelper;
GridConfig = gridConfig;
var retObj = Helper.Kendo().Grid(taskList)
.Name("AdraKendoGrid")
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("GetTaskResult", "Task"))
)
.Columns(ColumnsConfigurator)
.Groupable(gr => gr.Messages(message => message.Empty(Strings.kendoGroupMsg)))
.Pageable(pager => pager.PageSizes(new int[] { 15, 50, 100, 500 })
.Info(true)
.Messages(message => message.Display("{0} - {1} " + Strings.of + "{2} " + Strings.items))
.Messages(message => message.ItemsPerPage(Strings.itemsPerPage))
.Messages(message => message.Empty(Strings.noItemsToDisplay)))
.Resizable(r => r.Columns(true))
.Sortable()
.Reorderable(reorder => reorder.Columns(true))
.Resizable(r => r.Columns(true))
.ColumnMenu();
return retObj;
}
And finally, this is my controller action supposed to be called from the excel import button.
[HttpPost]
public ActionResult Excel_Export_Save(string contentType, string base64, string fileName)
{
var fileContents = Convert.FromBase64String(base64);
return File(fileContents, contentType, fileName);
}
But this controller action does not even get called when click the Excel Import button in the grid.
What am I doing wrong? Any suggestion is appreciated. Thank you.
After specifying this
.ToolBar(tools => tools.Excel())
.Excel(excel => excel
.AllPages(true)
.ProxyURL(Url.Action("Excel_Export_Save", "Task"))
);
and creating relevant Action Methods, should I do anything more?
I have tried lot of examples, but my button (Export to Excel) button does not do anything. I have imported the jsZip.js file (as specified in Kendo Demo) as well. I am following the below examples.
http://demos.telerik.com/aspnet-mvc/grid/excel-export
http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/excel-export
Any kind of help is appreciated. I am stucked here.
Upvotes: 0
Views: 5738
Reputation: 11
One solutions is:
<script src="//cdnjs.cloudflare.com/ajax/libs/jszip/2.4.0/jszip.min.js"></script>
Upvotes: 1
Reputation: 924
The issue was with the Kendo MVC version I was using. Excel export is supported from the Kendo 2014 Q3 (2014.3.1119) version.
Upvotes: 0