// This code doesn't remove first column
let params = {};
params = { allColumns: false };
this.agGridOptions.columnDefs[0]['hide'] = true; // To remove first column
this.agGridOptions.api.exportDataAsCsv(params);
Use columnKeys to provide the list of columns that you want to export.
So if you want to export all the visible columns except the first, get the list of visible columns using getAllDisplayedColumns(), then remove the first item from the list and pass this as the columnKeys to exportDataAsCsv(params) method.
Try this code:
exportCsv() {
var excelParams = {
columnKeys: ['firstName', 'middleName','lastName', 'dob'],
allColumns: false,
fileName: 'Student List.csv',
skipHeader: false,
customHeader: 'Student List' + '\n',
customFooter: '\n \n Total No.Of Students :' + this.gridOptions.api.getModel().getRowCount() + ' \n'
}
this.gridOptions.api.exportDataAsCsv(excelParams);
}
Mention the columns which want to be displayed in Excel should be defined in columnKeys