Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI Grid for MVC export to Excel does nothing

I am using Kendo grid for MVC 4.0. I have the latest DLL 2015.1.318.440. I am including jszip.js. I copied and pasted the code from the example:

          .ToolBar(tools => tools.Excel())
          .Excel(excel => excel.FileName("Enrollments.xlsx"))

It does nothing. The button changes color and that's it. I don't get any errors when I try it. It just doesn't do anything. I am not using a proxy server. I am running this in Chrome latest version.

The grid

@(Html.Kendo().Grid<Trawick.Agents.Models.EnrollmentPolicy>()
.Name("grid")
    .ToolBar(tools => tools.Excel())              
    .Excel(excel => excel
   .FileName("Enrollments.xlsx")
       .Filterable(true)
       .ProxyURL(Url.Action("Excel_Export_Save", "Enrollments"))
     )              
     .Columns(columns =>
      {
       columns.Bound(p => p.enrollment_date)
          })
     .Pageable()
     .Groupable()
     .Sortable()
     .DataSource(dataSource => dataSource
     .Ajax()
     .PageSize(20)
     .Read(read => read.Action("Enrollments_Read", "Enrollments")))
)

The controller

    [HttpPost]
    public ActionResult Excel_Export_Save(string contentType, string base64, string fileName)
    {
        var fileContents = Convert.FromBase64String(base64);

        return File(fileContents, contentType, fileName);
    }
    public ActionResult Enrollments_Read([DataSourceRequest]DataSourceRequest request, int? id)
    {
        string sql = "SELECT * FROM EnrollmentPolicy ";
        sql += SearchParams.SetSearch(this);
        return Json(GetEnrollments(sql).ToDataSourceResult(request));
    }

Bundle file including jszip

bundles.Add(new ScriptBundle("~/js/kendo")
     .Include("~/Scripts/jszip.js")
     .Include("~/Scripts/kendo.all.min.js")
     .Include("~/Scripts/kendo.aspnetmvc.min.js"));
like image 406
stuart Avatar asked Apr 15 '15 21:04

stuart


2 Answers

        bundles.Add(new ScriptBundle("~/js/kendo")
            .Include("~/Scripts/kendo.all.min.js")
            .Include("~/Scripts/kendo.aspnetmvc.min.js")
            .Include("~/Scripts/jszip.js"));

This was the issue.jszip has to be included AFTER the kendo scripts (this is the opposite of what the documentation says).

like image 168
stuart Avatar answered Sep 22 '22 06:09

stuart


My issue was related to volume - smaller number of records work, large batches do not. My current workaround is to set AllPages(false) and then it will just export a filtered list. See http://www.telerik.com/forums/excel-export-not-working-with-more-than-a-thousand-records

like image 45
Steve Greene Avatar answered Sep 19 '22 06:09

Steve Greene