Skip to content Skip to sidebar Skip to footer

Ag-grid Angular Format Data Before Exporting

I have grid which I want to export: Above there's example of two columns: one with timestamp, one with object. My export() method which I use to export as csv: export() { let h

Solution 1:

In your export() function, you will have to add a parameter processCellCallback.

Something like this:

export() {
    let header = this.columnDefs.map(columnDef => {
      let id = columnDef.field || columnDef.colId || columnDef.value;
      let headerName = columnDef.headerName;
        return headerName;
      });
      let a: any;
      let params: any = {
        fileName: 'export.csv',
        columnSeparator: ';',
        skipHeader: true,
        columnKeys: this.columnDefs.map(c => c.field || c.colId).filter(c => !!c)
      };
      params.customHeader = header.join(params.columnSeparator) + '\n';
      params.processCellCallback = function(cellParams) {
             if(cellParams && cellParams.column.colId === 'yourTimestampfield') {
                     return this.formatter; //apply your timestamp formatter      
             } else if(cellParams && cellParams.column.colId === 'yourObjectfield') {
                     return this.formatter; //apply your object formatter  
             } else 
                    return cellParams.value // no formatting
          }
      this.grid.api.exportDataAsCsv(params);
    }

Read more in the example and docs here.


Post a Comment for "Ag-grid Angular Format Data Before Exporting"