Error when exporting to csv with destinationType set to 'plain'

Answered
Raymond Halim asked on October 17, 2024

Hi,

I encountered the following error when exporting to csv with destinationType set to 'plain'

TypeError: Cannot read properties of undefined (reading 'coords')
... at PivotApi.l2.exportTo...

The code is as follows:

this._pivotTable!.exportTo('csv', {destinationType: 'plain'},
(result: any) => { // Get data }
);

Note that the flexmonster version used is 2.9.88

Please advise.  Thank you.

7 answers

Public
Maksym Diachenko Maksym Diachenko Flexmonster October 17, 2024

Hello, Raymond!

Thank you for reaching out to us.

This issue is most likely caused by the export process being started while the component has not finished loading. To overcome this issue, you should start the export after the Flexmonster grid is fully loaded. This can be achieved with the reportcomplete event, which is fired when the data is loaded successfully and the grid is rendered.

Please let us know if our recommendation helped you.

Best Regards,
Maksym

Public
Maksym Diachenko Maksym Diachenko Flexmonster October 29, 2024

Hello, Raymond!

Hope you are doing well.
We are wondering if our suggestion to delay the export with the reportcomplete event helped you.
Looking forward to hearing your feedback.

Best Regards,
Maksym

Public
Raymond Halim October 30, 2024

Hi Maksym,

Yes, that helped.  Thank you.

Public
Maksym Diachenko Maksym Diachenko Flexmonster October 30, 2024

Hello, Raymond!

Thank you for your reply.
We are glad to hear that our recommendation helped you.
Please let us know if more questions arise.

Best Regards,
Maksym

Public
Raymond Halim November 6, 2024

Hi Maksym,

When the view is compact, I need to expand the table first before exporting:

const onAfterGridDraw = () => {
	this._pivotTable!.off('aftergriddraw', onAfterGridDraw);
	this._pivotTable!.exportTo(
		'csv',
		{destinationType: 'plain'},
		(result: any) => {
			console.log(result.data);
		}
	);
};
this._pivotTable!.on('aftergriddraw', onAfterGridDraw);
this._pivotTable!.expandAllData();

However, result.data is empty string despite the table having data.

Public
Maksym Diachenko Maksym Diachenko Flexmonster November 7, 2024

Hello, Raymond!

Thank you for writing to us.

For this use case, we recommend expanding the data by using the expands.expandAll property as true. This way, the component will load all data and make it available for export on the reportcomplete event, as shown in this example: https://jsfiddle.net/flexmonster/dekfa35h/

Please let us know if this approach would work for you.

Best Regards,
Maksym

Public
Maksym Diachenko Maksym Diachenko Flexmonster 5 days ago

Hello, Raymond!

Hope you are doing well.
Just checking in to ask if you tried the suggested approach for expanding all cells upon Flexmonster loads.
Please let us know if this helped to resolve the issue with exporting.

Best Regards,
Maksym

Please login or Register to Submit Answer