AG-Grid skip column on export to CSV
Asked Answered
A

4

9

I have a column in a table which has only buttons in it. The button is a download button. I dont what this column to be exported when i click on export to csv. Can this be done?

Alurta answered 7/6, 2018 at 7:33 Comment(0)
S
10

This is what worked for me:

exportToExcel() {
var params = {
    columnKeys: ['FIELDA', 'FIELDB', 'FIELDC']
};
this.gridApi.exportDataAsCsv(params);
}

You get the fields from the ColumnDef

Spread answered 4/3, 2019 at 22:5 Comment(0)
A
3

You can specify which columns data you want in export while calling gridApi.exportDataAsCsv(params). You can mention that in columnKeys parameter.

params.columnKeys = ["country", "bronze"];
this.gridApi.exportDataAsCsv(params);

Reference: ag-grid: CSV export

Check the result - if you check Specify Columns checkbox, only the above mentioned columns will be there in the CSV.

Artwork answered 7/6, 2018 at 9:18 Comment(0)
D
1

Internally it search for colId of a particular column. AG Grid adds '_1' to every field as a unique colId.

Try this , It will work.

Under ColDefs , if your field name is : FieldA , FieldB.

const params = {
columnKeys: ['FieldA_1','FieldB_1'];
};
Decennium answered 23/10, 2019 at 13:4 Comment(0)
I
0

To avoid a 1st checkbox column in an export:

    exportToExcel() {
       let params = {
          columnKeys: this.gridApi.getColumns().slice(1).map((col: Column) => col.getColId())
        };

       this.gridApi.exportDataAsCsv(params);
    }
Immortal answered 17/4, 2024 at 15:2 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.