I add context menu and reassign export to csv and Excel - I need export use valueFormatter for some column.
Export working fine, but after I run export to xml, and then run export to Excel - I get xml file.
It's happen only here - because I use getContextMenuItems. Other tables uses standard context menu working fine.
menu:
getContextMenuItems = (() => {
const self = this;
return (param) => {
const menu = [
'copy',
'copyWithHeaders',
'paste',
'separator',
{
name: 'Export',
subMenu: [
{
name: 'csvExport',
action: () => {
self.gridApi.exportDataAsCsv({
processCellCallback: (params) => {
if (params.column.getColDef().valueFormatter) {
const valueFormatterParams: ValueFormatterParams = {
...params,
data: params.node.data,
// tslint:disable-next-line:no-non-null-assertion
node: params.node!,
colDef: params.column.getColDef()
};
return params.column.getColDef().valueFormatter(valueFormatterParams);
}
return params.value;
},
});
}
},
{
name: 'excelExport',
action: () => {
self.gridApi.exportDataAsExcel({
processCellCallback: (params) => {
if (params.column.getColDef().valueFormatter) {
const valueFormatterParams: ValueFormatterParams = {
...params,
data: params.node.data,
// tslint:disable-next-line:no-non-null-assertion
node: params.node!,
colDef: params.column.getColDef()
};
return params.column.getColDef().valueFormatter(valueFormatterParams);
}
return params.value;
},
});
}
},
'excelXmlExport'
]
}
];
return menu;
};
})();
Plunker for example: https://plnkr.co/edit/ysaS5IJzOwvVacRb
- run export to Excel (formated) - get xlsx
- run export to xml - get xml
- run export to Excel (formated) - get xml instead xlsx
In your customized Excel Export you got to define
exportModeproperty. the reason for explicitly defining this property is that AG Grid uses the same method to export both types andexportModeplays a crucial part here. if no export mode is defined then AG Grid usesthis.getExportMode()which gives last usedexportMode(in your case XML).this is how AG Grid has implemented Export functionality.
Change your code to this and it should work,