首页 > 解决方案 > 无法以角度 6 导出到剑道网格中的 excel 整个网格数据

问题描述

嗨,我正在尝试以角度使用剑道网格的导出到 excel 功能以下是我的 html 代码

HTML

<button type="button" kendoGridExcelCommand icon="file-excel">Export to Excel</button> 
<kendo-grid-excel fileName="Categories.xlsx" [fetchData]="allData"> 
</kendo-grid-excel>

打字稿

class {public gridData:any[];public allData(): ExcelExportData {
  const result: ExcelExportData =  {
      data: process(this.gridData, {
          sort: [{
             field: 'RequestNumber',
             dir:   'asc'
          }]
      }).data,
  };

  return result;
}
error :Cannot read property 'gridData' of undefined

参考这篇文章剑道出口

标签: angular

解决方案


“kendo-grid-excel”组件需要在 Grid 组件中,并且“this”对象应该指向“allData”方法中的实际组件——或者在构造函数中绑定它:

constructor() {
    this.allData = this.allData.bind(this);
}

...或使用箭头功能:

public allData = () => {
  // "this" will be the expected object here
}

推荐阅读