2016-02-04 147 views
7

我想用excel导出创建剑道网格。我的数据精确显示,因为我希望它和网格工作正常。但是,saveAsExcel函数会触发excelExport事件,但不会创建文件。与PDF导出同样的问题。 这里是我的网格选项:Kendo UI网格导出excel和pdf导出,没有文件创建

grid = $("#grid").kendoGrid({ 
     toolbar:["excel","pdf"], 
     height: 500, 
     scrollable: true, 
     groupable: true, 
     sortable: true, 
     filterable: false, 
     excel: { 
      allPages:true, 
      filterable:true 
     }, 
     excelExport: function(e) { 
      console.log('Firing Export'); 
      console.log(e.workbook); 
      console.log(e.data); 
     }, 
     pdfExport: function(e){ 
      console.log('PDF export'); 

     }, 
     columns: [ 
      { field: "date", title: "Time", template: "#= kendo.toString(kendo.parseDate(date), 'MM/dd/yyyy') #", width: '120px'}, 
      { field: "customer", title: "Customer" }, 
      { field: "amount", title: "Total", format: "{0:c}", width: '70px', aggregates: ["sum"]}, 
      { field: "paid_with", title: "Payment", width: '130px'}, 
      { field: "source", title: "Source" }, 
      { field: "sale_location", title: "Sale Location" } 
     ] 
    }).data("kendoGrid"); 

每当数据搜索参数发生变化,该AJAX调用。在哪里刷新数据源。

 $.ajax({ 
      'url':'/POS/ajax/loadTransactionsDetailsForDay.php', 
      'data':{ 
       filters 
      }, 
      'type':'GET', 
      'dataType':'json', 
      'success':function(response) { 
       var dataSource = new kendo.data.DataSource({ 
        data: response.data.invoices, 
        pageSize: 100000, 
        schema: { 
         model: { 
          fields: { 
           date: {type: "string"}, 
           customer: { type: "string" }, 
           amount: { type: "number" }, 
           paid_with: {type: "string"}, 
           source: {type:"string"}, 
           sale_location: {type:"string" } 
          } 
         } 
        } 
       }); 
       grid.setDataSource(dataSource); 
       grid.refresh(); 
      } 

     }); 

我的控制台日志的输出是。

Firing Export. 

工作表对象。

Object {sheets: Array[1]}sheets: Array[1]0: Objectlength: 1__proto__: Array[0]__proto__: Object 

,并和阵列与这些对象在网格中的每一行:

0: o 
    _events: Object 
    _handlers: Object 
    amount: 40.45 
    customer: "customer 1" 
    date: "2015-11-25T00:00:00-08:00" 
    dirty: false 
    employee: 23 
    paid_with: "Check" 
    parent:() 
    sale_location: "Main" 
    source: "POS" 
    uid: "70b2ba9c-15f7-4ac3-bea5-f1f2e3c800d3" 

我有最新版本的剑道,我加载jszip。我在最新版本的Chrome上运行它。 我已经试过了我能想到的代码的各种变体,包括删除我的模式,每次在回调中重新初始化kendo。

任何人都知道为什么这不起作用?

在这个例子中,我可以找到它的每一个例子,使它看起来超级简单,只需创建网格和调用导出...所以我必须忽略一些东西。

我很感激任何关于此的想法。

谢谢。

+0

您的实施似乎没问题。你确定jszip是在剑道之前加载的吗? –

+0

我复制了你的JavaScript,它工作正常(与一个空文件)。这可能是权限问题吗?我的文件被写入我的下载文件夹。 – Fruitbat

+0

@The_Black_Smurf是的,它之前加载。 我有一个时间限制,所以我最终写了一个网格的CSV导出。但会回到这个并试图找出造成它的原因。 – Svennisen

回答