0

// 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);  

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

For furthar help let columnsKeys = this.agGridOptions.columnApi.getAllDisplayedColumns(); let columnIds: Array<any> = []; columnsKeys.forEach(keys => { let columnName: string = keys.getColId(); if (columnName != '0' && columnName) { columnIds.push(columnName); } }); return columnIds; params['columnKeys'] = columnIds;
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.