I came across another issue, when i pass the output of my query which is the below sample i get [object Object],[object Object],[object Object] in the emails column. How can i fixed that or does exporter have no way of handling arrays in a field ?
{ "DocId": "farm::4DA8DC94-D10B-4962-A920-775F0A86FB5A", "baths": 2, "beds": 2, "city": "Los Angeles", "emails": [ { "default": "demo1@test.com" }, { "default": "demo2@test.com" }, { "default": "demo3@test.com" } ] }
Hi Alex,Thank you for contacting Infragistics!You can modify the data in the row by attaching to the `onRowExporting` event of the `IgxExcelExporerService`.In this case, you can define a transform function that reduces your e-mail array to a string:
const formatEmails: (arr: { "default" : string }[]) => string = (arr: { "default" : string }[]) => arr.map(e => e["default"]).reduce((e, i) => e + i + "; ", "");
Then, when exporting, subscribe to the `onRowExporting` event and transform the data inside the 'emails' field:
this.excelExportService.onRowExport.pipe(takeUntil(this.destroy$)).subscribe((args: IRowExportingEventArgs) => { args.rowData["Emails"] = args.rowData["Emails"].map(e => e["default"]).reduce((e, i) => e + i + "; ", ""); })
Here is a working StackBlitz example you can check out.Hope this helps!
Thanks, that gets me closer but here are some additional questions...
a) Is there a way to pass the Arrange data dynamically, when calling the export function
b) Not sure what this part is doing in the sample code
this.excelExportService.onColumnExport.pipe(takeUntil(this.destroy$)).subscribe((args: IColumnExportingEventArgs) => { if (args.field === "name") { args.header = "Name" } })
i assumed it would change the column Header from name to Name. If that's the case that's not working
c) lets say i am your example which we have as age is actually money and i would show it on the excel export as $ 25.00 for example how would i do that and how can i pass format info for certain fields dynamically
I am trying to create a module which will be able to be reused and does not have to be specific for a single export which means i want to be able to pass the column to export, column order, heading as well as column format when calling the export function. Also i hope the same concept as far as transformation apply s to the csv export
Thanks for taking the time to check the example!a) You can pass `arrangeData` inside of the `exportData` call and transform function through Array.map of the array you want to change:
this.excelExportService.exportData(this.localData.map(e => arrangeData(e)), new IgxExcelExporterOptions("ExportFileFromData"));
b) An oversight, sorry for the confusion. It's now fixedc) You can again transform the data you want to be output in the export file. In the case of $25.00, you can do:
(e: number) => '$' + e.toFixed(2);
You can also refer to my reply in your other thread regarding the difference between the ExcelExporterService and the Excel Library.
Hope this helps!