BoldDesk®Customer service software offering ticketing, live chat, and omnichannel support, starting at $49/mo. for 10 agents. Try it for free.
As the subject says, how do you do an excel export for a grid but exclude the groups?
Hi Mark,
Greetings from Syncfusion support.
Query: EJ2 Grid Excel Export without groupings
As per your query that you need to export the excel file without the grouped data. We have achieved your requirement using dataSource property of excelExportProperties which is passing on excelExport methos in toolbarClick event.
toolbarClick: function () { var exportProperties = { dataSource: window.inventoryData, }; this.excelExport(exportProperties); } |
Sample: https://stackblitz.com/edit/swnfgf-kulxct?file=index.js
Please get back to us if you need further assistance on this.
Regards,
Mohammed Ansar.
This is not working can you implement the same for a react grid component
Hi Nandhini,
Greetings from Syncfusion Support.
Regarding your requirement to export the EJ2 Grid to an Excel file without grouping, we achieve this by temporarily removing the group settings before export and then restoring them once the export is complete. Below is a detailed breakdown of the implementation:
toolbarClick
EventThe
toolbarClick
event is triggered
when the user clicks an export button (Excel,
PDF, or CSV) from the toolbar.
function toolbarClick(args) { switch (args.item.id) { case 'DefaultExport_pdfexport': gridInstance.pdfExport(); break; case 'DefaultExport_excelexport': gridInstance.excelExport(); break; case 'DefaultExport_csvexport': gridInstance.csvExport(); break; } }
|
args.item.id
property determines which export type was selected.excelExport()
method for Excel exportbeforeExcelExport
EventBefore exporting to Excel, we need to remove the grouping so that the exported file contains only raw data.
function beforeExcelExport(args) { // Store the current grouping state groupedColumns = gridInstance.groupSettings.columns; // Clear grouping gridInstance.setProperties( { groupSettings: { columns: [], }, }, true ); }
|
groupSettings.columns
) in a variable (groupedColumns
).groupSettings.columns
= []
.true
in setProperties
ensures that changes
are applied without re-rendering the grid.excelExportComplete
EventAfter the export is completed, we restore the original grouping settings to bring back the grouped view in the UI.
function excelExportComplete(args) { gridInstance.setProperties( { groupSettings: { columns: groupedColumns, }, }, true ); }
|
groupedColumns
).To
see this in action, you can refer to the following sample project:
Sample: https://stackblitz.com/edit/react-mjxayypa-mhsmfdoy?file=index.js
toolbarClick
event is triggered.beforeExcelExport
): excelExportComplete
): Regards,
Joseph I.