ag-grid csv export - formatting with processCellCallback
Asked Answered
W

1

5

I want to format values before exporting them to CSV. For this, I use the processCellCallback as shown in the Code sample. When I include the Callback, I get empty strings instead of cell value for every cell in my ag-grid. For this, I followed the example on the ag-grid Site https://www.ag-grid.com/javascript-grid-export/ and the StackOverflow article Ag-grid angular format data before exporting

For debugging purpose I commented everything out except the return and included a console.log

The Cell Value is written in the log, but my export CSV has only empty columns. I remove the processCellCallback in the params the value are properly exported.

ExportToCsv(gridApi: any, exportFileName: string){
    var params = {
      fileName: exportFileName
      ,columnSeparator: ';'
      ,processCellCallback: (params) => {this.processCells(params)}
    }
    gridApi.exportDataAsCsv(params);
  }
  processCells(params: any) {
    console.log(params.value);
    return params.value;
  }
Warmblooded answered 7/10, 2019 at 8:53 Comment(0)
P
6

processCellCallback must return a string. However in your code, the anonymous function returns nothing.

Change:

processCellCallback: (params) => {this.processCells(params)}

to

processCellCallback: (params) => this.processCells(params)

or for simplicity:

processCellCallback: this.processCells
Photolysis answered 7/10, 2019 at 19:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.