Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
30
Arrays in a column with multiple values
posted

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"
		}
	]
}

Parents
No Data
Reply
  • 80
    Offline posted

    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!

Children