Thanks for contacting Syncfusion support.
Kindly add the column fields based on the data source dynamically using following code example. Here we have modified data source in drop down list and validated the season field in data source. And add/remove the validated column field to pivot table.
Code Example:
|
onChange(args: ChangeEventArgs): void {
if (args.value === "DataSource2") {
this.pivotObj.dataSourceSettings.dataSource = Pivot_Data2;
var dataKeys = Object.keys(this.pivotObj.dataSourceSettings.dataSource[1]);
if ((dataKeys as any).includes("season"))
this.pivotObj.dataSourceSettings.columns.push({ name: 'season' });
}
else {
this.pivotObj.dataSourceSettings.dataSource = Pivot_Data1;
var columns = this.pivotObj.dataSourceSettings.columns;
for (var i = 0; i < columns.length; i++) {
if (columns[i].name === "season")
this.pivotObj.dataSourceSettings.columns.pop();
}
}
}
|
Meanwhile, we have prepared a sample for your reference. Please check the below sample link.
We hope the above sample meets your requirements.
Regards,
Sivamathi.