I set up a kendo grid and configured all the rows of the table and the header. When I click the export button, it generates an excel file. But where the problem arises, I do not know, with the same configuration that I did in IE, instead of generating the file, I showed the data format in the URL with 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");
Click the "Export data to table" button in 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(); });