Rob Shepherd
Rob Shepherd

Reputation: 41

ag-Grid Export To CSV not showing correct filename

I am writing code in Typescript using Angular 2 and ag-Grid (not enterprise version).

I am having a problem with the export functionality of ag-Grid and was hoping someone could help.

With just one Grid on the form I can export without any problems. When I introduce a second grid I can also export but the file filename is not correct (it defaults to export.csv).

Here is some example code.

Note that in the html I set:

[gridReady] = "onGridReadyTest1($event)" for the first grid

[gridReady] = "onGridReadyTest2($event)" for the second grid

public gridApiTest1; public gridApiTest2; ...

onGridReadyTest1(params){
  this.gridApiTest1 = params.api;
}

onGridReadyTest2(params){
  this.gridApiTest2 = params.api;
}

btnClickExportTest1 = function () {

   var params = {
     skipHeader: false,
     skipFooters: true,
     allColumns: true,
     onlySelected: false,
     suppressQuotes: true,
     filename: 'test1.csv',
     columnSeparator: ','
   };

   this.gridApiTest1.exportDataAsCsv(params);

}

btnClickExportTest2 = function () {

   var params = {
     skipHeader: false,
     skipFooters: true,
     allColumns: true,
     onlySelected: false,
     suppressQuotes: true,
     filename: 'test2.csv',
     columnSeparator: ','
   };
   this.gridApiTest2.exportDataAsCsv(params);

}

As I mentioned, the export actually works with the correct data from the relevant grid. Its just the filename is correct for the first grid and incorrect for the second (export.csv)?

What I am doing wrong? Any help would be appreciated.

Thanks

Upvotes: 2

Views: 6363

Answers (1)

healthy_meerkat
healthy_meerkat

Reputation: 132

Change your params filename from "filename: " to "fileName: "

As per:

https://www.ag-grid.com/javascript-grid-export/

Upvotes: 3

Related Questions