【发布时间】:2016-02-04 18:52:59
【问题描述】:
我正在尝试使用 excel 导出创建剑道网格。我的数据完全按照我的意愿显示,并且网格工作正常。但是,saveAsExcel 函数会触发 excelExport 事件,但不会创建文件。 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 上运行它。 我已经尝试了我能想到的各种代码变体,包括删除我的模式,每次在回调中重新初始化剑道。
有人知道为什么这不起作用吗?
我能找到的每个例子都让它看起来超级简单,只需创建网格并调用导出......所以我必须忽略一些东西。
我很感激对此的任何想法。
谢谢。
【问题讨论】:
-
您的实现似乎没问题。你确定jszip是在剑道之前加载的吗?
-
我复制了你的 javascript,它工作正常(使用空文件)。这可能是权限问题吗?我的文件已写入我的下载文件夹。
-
@The_Black_Smurf 是的,之前加载过。我有时间限制,所以我最终改为编写网格的 CSV 导出。但会回到这一点并尝试找出导致它的原因。
-
@Fruitbat 我可以不通过 Kendo 生成其他文件。所以我认为这不是权限错误。
标签: javascript ajax kendo-ui kendo-grid