Search code examples
angularag-gridag-grid-angular

ag-grid csv export - formatting with processCellCallback


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;
  }

Solution

  • 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