Need a special offer?Find out if your project fits.
+

how to export in flexmonster on mobile integrated in framework (Angular/Ionic)

Answered
CHUBB LIFE INSURANCE VIETNAM COMPANY asked on August 19, 2021

Hi Flexmonster team,
I'm having an export problem in flexmonster on mobile. Can we export on mobile with ionic framework? According to the flexmonster source code I read, I see that export in the toolbar has a mobile field is false. I tried using the export functions in the toolbar for mobile, but after I finished using it, there were some errors like can't return, nothing happens, can't export file,...
Any answer in this situation?
Hope to hear from you soon.
Regards,
Tung.

1 answer

Public
Illia Yatsyshyn Illia Yatsyshyn Flexmonster August 19, 2021

Hello,
 
Thank you for posting on our forum.
 
By default, Flexmonster only supports a browser environment for saving files to the local system. If the used mobile framework seems to be incompatible with the browser environment in terms of saving, we suggest using the plain export provided by Flexmonster.
 
Set the destinationType parameter of the exportTo API call to plain in order to retrieve exported data but prevent the default saving process. The exported data will be passed to the callback where you can save it in a way native to your environment.
 
For example, HTML and CSV will be represented as a simple string that allows you to save these types of export as simple text files with corresponding extensions.
 
Excel export will be returned as Uint8Array. Use it to create Blob and save it as a binary file.

flexmonster.exportTo(type, params, (result) => {
if(type === "excel") {
result.data = Buffer.from(Array.from(result.data));
result.type = "xlsx";
}
...
/* save to local system */
}

 
Images are represented as HTMLCanvasElement and can be converted using the toDataURL method. Next, it can be converted to Blob.

flexmonster.exportTo(type, params, (result) => {
  if(type === "image") {
result.data = Buffer.from(result.data.toDataURL.replace(/^data:image\/\w+;base64,/, ""), 'base64');
result.type = "png";
  }
...
/* save to local system */
}

 
Finally, the PDF export is returned as a jsPDF object. You can retrieve the corresponding string using the output method of its object.

flexmonster.exportTo(type, params, (result) => {
  if(type === "pdf") {
result.data = result.data.output();
  }
...
/* save to local system */
}

 
Saving itself can be performed using any corresponding Ionic library allowing to operate with a local file system.
 
We hope it helps.
 
Kind regards,
Illia

Please login or Register to Submit Answer