Jonathan Brou Jonathan Brou - 5 months ago 48
AngularJS Question

exportDataAsCsv is not supported property or method of gridOptions.api

According to AG-Grid docs here there is a method on the gridOptions.api that allows data export of the table contents. However, whenever I run the function, I simply get the error

Object doesn't support property or method 'exportDataAsCsv'

It's running in a directive that looks a little like this:

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;

And my html looks like this:

<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" />
<div ag-grid="gridOptions" class="ag-blue" style="height:100%"></div>

The grid runs fine, but for some reason it doesn't believe that this method exists. Any ideas on why that might be? I'm using version 1.12 of ag-grid. I'm assuming my references are all good, or else I wouldn't get a grid to show at all.


exportDataAsCsv() wasn't introduced until version 2.0. You'll need to upgrade to a newer version of ag-grid which is now at v5.x.

If you're absolutely stuck with v1.12, it shouldn't be too hard to write your own CSV data exporter.

Here's a proof of concept on JSFiddle that converts JSON data to CSV format and exports it so the user can save it. To use this, you'll just need to give it the data from the ag-grid (or from your own data model that you supplied to ag-grid in the first place).

Export ag-grid data as CSV