我已经配置了剑道网格并配置了所有表格行和标题。当我单击导出按钮时,它正在生成一个 excel 文件。但是问题发生在哪里我不知道我在 IE 中所做的相同配置而不是生成文件它在 URL 中显示数据格式data:application/vnd.ms-excel,<table><tr><th>OrderID</th><th>Freight</th>.....
var grid = $("#grid").kendoGrid({
dataSource: {
type : "odata",
transport : {
read: "http://demos.kendoui.com/service/Northwind.svc/Orders"
},
schema : {
model: {
fields: {
OrderID : { type: "number" },
Freight : { type: "number" },
ShipName : { type: "string" },
OrderDate: { type: "date" },
ShipCity : { type: "string" }
}
}
},
pageSize : 10
},
filterable: true,
sortable : true,
pageable : true,
columns : [
{
field : "OrderID",
filterable: false
},
"Freight",
{
field : "OrderDate",
title : "Order Date",
width : 100,
format: "{0:MM/dd/yyyy}"
},
{
field: "ShipName",
title: "Ship Name",
width: 200
},
{
field: "ShipCity",
title: "Ship City"
}
]
}).data("kendoGrid");
按钮单击以将网格数据导出到 Excel。
$("#btnExport").click(function(e) {
var dataSource = $("#grid").data("kendoGrid").dataSource;
var filteredDataSource = new kendo.data.DataSource( {
data: dataSource.data(),
filter: dataSource.filter()
});
filteredDataSource.read();
var data = filteredDataSource.view();
var result = "data:application/vnd.ms-excel,";
result += "<table><tr><th>OrderID</th><th>Freight</th><th>Order Date</th><th>Ship Name</th><th>Ship City</th></tr>";
for (var i = 0; i < data.length; i++) {
result += "<tr>";
result += "<td>";
result += data[i].OrderID;
result += "</td>";
result += "<td>";
result += data[i].Freight;
result += "</td>";
result += "<td>";
result += kendo.format("{0:MM/dd/yyyy}", data[i].OrderDate);
result += "</td>";
result += "<td>";
result += data[i].ShipName;
result += "</td>";
result += "<td>";
result += data[i].ShipCity;
result += "</td>";
result += "</tr>";
}
result += "</table>";
if (window.navigator.msSaveBlob) {
window.navigator.msSaveBlob(new Blob([result]),'export.xls');
} else {
window.open(result);
}
e.preventDefault();
});