7

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"));
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
stuart
  • 215
  • 2
  • 8
  • It's very hard to answer this question. post more code or give more info. – IndieTech Solutions Apr 15 '15 at 21:20
  • Post the entire code you used – IndieTech Solutions Apr 15 '15 at 21:23
  • Where are you putting those lines of code? – Nathaniel Ford Apr 15 '15 at 23:38
  • The `_Save` method isn't needed in most browsers, it exists only for those browsers that don't allow saving from javascript. Debug your javascript code (eg by using the F12 tools of your browser) to find any javascript errors that prevent your code from working. Also try using Fiddler or the Network Capture functionality of your browser to see whether the Ajax call for the data succeeds or not – Panagiotis Kanavos Apr 16 '15 at 12:48
  • 1
    I've tried it both ways. F12 doesn't reveal any js errors; HOWEVER, when clicking the button, Fiddler shows NO activity at all from that action. Hmmm... – stuart Apr 16 '15 at 13:25
  • I tried it with ForceProxy set to true and it still doesn't call the controller method. I'm betting the problem is not with the export function, but with the toolbar button. – stuart Apr 16 '15 at 13:33
  • Can you try with including jszip from any of the CDN. http://cdnjs.cloudflare.com/ajax/libs/jszip/2.4.0/jszip.js or http://cdn.kendostatic.com/2014.3.1029/js/jszip.min.js – Amal Dev Apr 17 '15 at 03:49
  • I tried both, in the bundle and at the top of the page where the grid is. Still the button does nothing. This is a trial version of Kendo, but I understand that to be fully functional... – stuart Apr 17 '15 at 14:11

4 Answers4

13
        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).

stuart
  • 215
  • 2
  • 8
1

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

Steve Greene
  • 12,029
  • 1
  • 33
  • 54
0

As per the documentation, you need to do like this I think.

Controller

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

        return File(fileContents, contentType, fileName);
    }

cshtml

 .Excel(excel => excel
    .FileName("Enrollments.xlsx")
    .Filterable(true) //omit this if you don't need filtering in excel
    .ProxyURL(Url.Action("Excel_Export_Save", "Grid")) // for browsers not supporting saving file from JS
 )

Refer the demo code here and for documentation, go through this link

Amal Dev
  • 1,938
  • 1
  • 14
  • 26
  • 1
    This isn't needed. This is the *fallback* code in case saving from Javascript fails. It's even mentioned in the comments of the cshtml code. This will only help if the browser can't actually save from Javascript. All modern browsers support this though – Panagiotis Kanavos Apr 16 '15 at 12:42
0

I had the same problem just now - Export button doing nothing. I was running the Q3 2014 version of Kendo.

Upgrading to the latest DLL and updating to the latest JavaScript libraries and styles fixed this for me.

Christh
  • 517
  • 4
  • 9