I am using ag-grid in my application, on the top of the grid i have provided 2 buttons 'Download Excel' and 'Download CSV', when the user clicks on any of the button the data in the grid should be downloaded in the repective file format.
Using Angular i created a function which gets triggered when the user clicks on 'Download Excel' button.
downExcelFile()
{
var params = {
columnKeys: ['firstName', 'lastName', 'email', 'mobile', 'email'],
allColumns: false,
skipHeader: false,
skipFooters: true,
onlySelected: false,
suppressQuotes: true,
columnSeparator: ','
};
this.gridApi.exportDataAsExcel(params);
}
The problem i am facing is that on my grid i am showing 'email' and 'user id' columns but both of them have the same email values in those columns.. which means internally both the columns have same field email.
Now when define the columnKeys i am specifying email 2 times and in the excel i am getting the column headers as Email 2 times, instead i want to display the last column header as UserId
Any suggestions on how this can be achieved ?
Yes you can achieve header cutomization by using callback function processHeaderCallback() visit OfficialDocumentationLink for more deatil
This callback function is triggered for each column, even if the column is skipped for Excel as per config so the trick is identifying the column you want to change the header for. I achieved this by using a counter in my example.
Here is the demo that I created by forking into the example given in their official documentation.