不支持exportDataAsCsv属性或gridOptions.api的方法

时间:2016-08-08 20:46:39

标签: angularjs ag-grid

根据AG-Grid docs here,gridOptions.api上有一个方法,允许数据导出表内容。但是,每当我运行该函数时,我只会得到错误Object doesn't support property or method 'exportDataAsCsv'

它在一个看起来有点像这样的指令中运行:

app.directive('myDirective', function() {
restrict: 'E',
template-url: "blah.html",
link:{pre: function(scope,ele){
    var columnDefs = [
        { headerName: "Management Name", field: "ManagementName", width: 300 },
        { headerName: "Location", field: "Location", width: 150 },
        { headerName: "Backend System", field: "Vendor", width: 110 },
        { headerName: "Total Active Sites", field: "TotalActiveSites", width: 110 }
    ];
    scope.gridOptions = { columnDefs: columnDefs, rowData: null }
}, 

post: function (scope,ele) {
    scope.exportCsv = function() { scope.gridOptions.api.exportDataAsCsv(); }
    scope.gridOptions.rowData = dataList;
    scope.gridOptions.api.onNewRows();
}

我的HTML看起来像这样:

<input placeholder="Filter..." type="text" ng-model="gridOptions.quickFilterText" />
<button ng-click="exportCsv()">
    <img id="btnExportToExcel" alt="CSV File" src="../images/Excel.gif" style="cursor:pointer;" tooltip-placement="bottom" uib-tooltip="Excel" />
</button>
<div ag-grid="gridOptions" class="ag-blue" style="height:100%"></div>

网格运行良好,但由于某种原因,它不相信此方法存在。关于为什么会这样的任何想法?我正在使用版本1.12的ag-grid。我假设我的参考文献都很好,否则我根本就不会显示网格。

1 个答案:

答案 0 :(得分:0)

直到版本2.0,

exportDataAsCsv()才被引入。您需要升级到更新版本的ag-grid,现在是v5.x.

如果您完全坚持使用v1.12,那么编写自己的CSV数据导出器应该不会太难。

这里是JSFiddle的概念证明,它将JSON数据转换为CSV格式并将其导出,以便用户可以保存它。要使用它,您只需要从ag-grid(或者您自己提供给ag-grid的数据模型)中提供数据。

Export ag-grid data as CSV

相关问题