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。
任何人都知道爲什麼這不起作用?
在這個例子中,我可以找到它的每一個例子,使它看起來超級簡單,只需創建網格和調用導出...所以我必須忽略一些東西。
我很感激任何關於此的想法。
謝謝。
您的實施似乎沒問題。你確定jszip是在劍道之前加載的嗎? –
我複製了你的JavaScript,它工作正常(與一個空文件)。這可能是權限問題嗎?我的文件被寫入我的下載文件夾。 – Fruitbat
@The_Black_Smurf是的,它之前加載。 我有一個時間限制,所以我最終寫了一個網格的CSV導出。但會回到這個並試圖找出造成它的原因。 – Svennisen