Kendo UI Excel导出,生成多个文件,没有正确刷新?

我有一个单页的应用程序,通常会创build一个数组的新数据

var searchData = new kendo.data.DataSource({data:buildData});

然后在网格中显示它,

这一切看起来不错,除了出口的错误如下:

运行一个search和Excel导出工作正常。

运行第二次search和Excel导出下载2个文件,第一个是重复的第一个search的结果,第二个文件是新的search。

运行第三次search和Excel导出三个文件….等等…

它似乎刷新不适合我,但我不知道为什么不呢?

if(searchedArray) { searchedArray.forEach(function (row) { buildData.push({r:rowCount,w:row['w'],n:'1',nl:'2',o:row['o'],t:row['t'],d:row['d']; rowCount++; }); } var searchData = new kendo.data.DataSource({data: buildData}); var sGrid=null; sGrid = $("#searchedgrid").kendoGrid({ toolbar: ["excel"], excel: { fileName: "filename.xlsx", proxyURL: "http://demos.telerik.com/kendo-ui/service/export", filterable: true }, dataSource: searchData, sortable: { mode: "multiple", allowUnsort: true }, schema: { model: { fields: { r: { type: "number" }, w: { type: "number" }, n: { type: "string" }, nl: { type: "string" }, o: { type: "string" }, t: { type: "string" }, d: { type: "date" } } } }, height: sHeight, scrollable: true, pageable: false, selectable: "multiple cell", allowCopy: true, columns: [ { field: "r",width: 40,title: "Rank",template:'<center>#=r#</center>'}, { field: "w",width: 50,title: "Weight",template:'<center>#=w#</center>'}, { field: "n", title: "Number", width: "80px",template:'<center>#=n#</center>'}, { field: "nl", title: "&nbsp;", width: "14px",template:'<center><a href="#=nl#" onclick="javascript:void window.open(\'#=nl#\',\'details\',\'width=800,height=600,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0\');return false;"><div class="ambLink" id="detaillink" title="View details"></div></a></center>',sortable:false}, { field: "o",width: 200,title: "Owner"}, { field: "t",width: 400,title: "Title", attributes: {style: 'white-space: nowrap '} }, { field: "d",width: 70,title: "Filed",template:'<center>#=d#</center>'} ] }).data("kendoGrid"); $("#searchedgrid").data('kendoGrid').refresh(); 

出于某种原因,如果没有适当的内务pipe理,KendoGrid再加上导出到excel的function会错过多次初始化网格。

我做了什么来解决它是只创build一次网格:

 $("#grid").kendoGrid({ columns: [ (FIELDS LIST) ], groupable: false, pageable: true, scrollable: true, filterable: false, sortable: true, pageSize: 50 }); 

然后,重置实际callback事件上的数据源,就像您已经在做的那样。

  // Set Grid data source $("#grid").data("kendoGrid").setDataSource( new kendo.data.DataSource({ //Set the data of the grid as the result array of object. data: result.customerStatus }) ); $("#grid").data("kendoGrid").refresh(); 

不知何故我通过清除创build网格的div来解决问题。

加:

 document.getElementBy("grid").innerHTML = ""; 

之前:

 $("#grid").kendoGrid({ ...... });