Array in data

I'm testing pivot table and I have this data, but in the pivot change to research_outout array to string.

[{
  "score"24.1,
  "research_output": ["Very High""Extreme"]
},
{
  "score"4.1,
  "research_output": ["Low"]
},
{
  "score"2.1,
  "research_output": ["High""Low"]
}]

1 Reply

AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team May 22, 2024 09:00 AM UTC

Hi Jose,


We regret to let you know that currently, we don’t have direct support to bind the complex data/ data arrays (arrays of field values) to the pivot table. However, if you need to bind an array of values in the pivot table, you must convert the array of values into separate objects as JSON data. Then using that JSON data as a data source, you can render the Pivot Table component and perform additional actions. In the code example below, we have transformed the provided data source into the correct format and assigned it to the pivot table within the load event.


Code example:

  public data: any = [

        {

          "score": 24.1,

          "research_output": ["Very High", "Extreme"]

        },

        {

          "score": 4.1,

          "research_output": ["Low"]

        },

        {

          "score": 2.1,

          "research_output": ["High", "Low"]

        }

      ];

    load(args: any) {

        const jsonData = this.data.flatMap(item =>

            item.research_output.map(value => ({

              score: item.score,

              research_output: value

            }))

          )

        args.dataSourceSettings.dataSource = jsonData;

    }


Output screenshot:


Meanwhile we have prepared a sample for your reference.


Sample: https://stackblitz.com/edit/angular-8qqc8y-hhtzwy?file=src%2Fapp.component.ts,src%2Fapp.component.html


Also, Please refer the below documentation for more details.


Document: https://ej2.syncfusion.com/angular/documentation/pivotview/how-to/bind-complex-data-to-the-pivot-table

Please let us know if you have any concerns.


Regards,

Angelin Faith Sheeba.


Loader.
Up arrow icon