2

我的应用程序中有剑道网格和导出按钮。导出网格数据工作正常,但这里有些行重复,它们显示在文件的末尾。在这里我为导出的文件提供了自定义名称。谁能告诉我我的代码有什么问题。请?这是导出按钮点击代码

      $("#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>";
 var dt = new Date();
    var day = dt.getDate();
    var month = dt.getMonth() + 1;
    var year = dt.getFullYear();
    var hour = dt.getHours();
    var mins = dt.getMinutes();
    var postfix = day + "." + month + "." + year + " " + hour + ":" + mins;
    var a = document.createElement('a');
  var table_div = (document.getElementById('grid').getElementsByTagName('tbody')[0]);
var table_html = table_div.outerHTML.replace( );
 a.href = result + ',' + table_html;
      a.download = 'exporteddata@'  +postfix+ '.xls';
    a.click();
 e.preventDefault();
                                                    });

这是小提琴http://jsfiddle.net/SZBrt/35/

4

1 回答 1

4

将其修改为小提琴代码:

   for (var i = 0; i < data.length-1; i++) 
   {
       //your code
   } 

   for (var i = 0; i < data.length; i++) 
   {
       //your code
   } 
于 2013-03-26T07:17:44.010 回答