Ag-grid angular format data before exporting

前端 未结 1 1577
粉色の甜心
粉色の甜心 2021-01-21 07:21

I have grid which I want to export:

相关标签:
1条回答
  • 2021-01-21 07:50

    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.

    0 讨论(0)
提交回复
热议问题