Having trouble getting help?
Contact Support
Contact Support
Export table and chart into the same document using toolbar
27 Apr 20244 minutes to read
Even if the displayOption.view property is set to Both in the pivot table, you can only export either the table or the chart to the PDF document based on the current value set in the displayOption.primary property. But, to export both the table and the chart to the same PDF document, use the pdfExport method during the actionBegin event invoke.
In the following example, the built-in export action can be restricted by setting the args.cancel option to true in the actionBegin event, and both the table and the chart can be exported by calling the pdfExport method and setting the exportBothTableAndChart
argument to true.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { PivotViewAllModule, PivotFieldListAllModule } from '@syncfusion/ej2-angular-pivotview'
import { Component, ViewChild, OnInit } from '@angular/core';
import {
PivotView, FieldListService, IDataSet, IDataOptions, PDFExportService,
PivotActionBeginEventArgs, ToolbarItems, DisplayOption, ToolbarService, PivotChartService
} from '@syncfusion/ej2-angular-pivotview';
import { ChartSettings } from '@syncfusion/ej2-pivotview/src/pivotview/model/chartsettings';
import { Pivot_Data } from './datasource';
@Component({
imports: [
PivotViewAllModule,
PivotFieldListAllModule
],
standalone: true,
selector: 'app-container',
providers: [FieldListService, ToolbarService, PDFExportService, PivotChartService],
// specifies the template string for the pivot table component
template: `<ejs-pivotview #pivotview id='PivotView' [dataSourceSettings]=dataSourceSettings allowPdfExport='true'
showFieldList='true' width='100%' [displayOption]='displayOption' height='350' [toolbar]='toolbarOptions' showFieldList='true'
(actionBegin)='actionBegin($event)' showToolbar='true' [chartSettings]='chartSettings'></ejs-pivotview>`
})
export class AppComponent implements OnInit {
public dataSourceSettings?: IDataOptions;
public toolbarOptions?: ToolbarItems[];
public displayOption?: DisplayOption;
public chartSettings?: ChartSettings;
actionBegin(args: PivotActionBeginEventArgs): void {
if (args.actionName == 'PDF export') {
args.cancel = true;
this.pivotGridObj.pdfExport({}, false, undefined, false, true);
}
}
@ViewChild('pivotview', { static: false })
public pivotGridObj?: any;
ngOnInit(): void {
this.displayOption = { view: 'Both' } as DisplayOption;
this.toolbarOptions = ['Grid', 'Chart', 'Export', 'FieldList'] as ToolbarItems[];
this.chartSettings = { chartSeries: { type: 'Column' }} as ChartSettings;
this.dataSourceSettings = {
dataSource: Pivot_Data as IDataSet[],
expandAll: false,
enableSorting: true,
columns: [{ name: 'Year', caption: 'Production Year' }, { name: 'Quarter' }],
values: [{ name: 'Sold', caption: 'Units Sold' }, { name: 'Amount', caption: 'Sold Amount' }],
rows: [{ name: 'Country' }, { name: 'Products' }],
formatSettings: [{ name: 'Amount', format: 'C0' }],
filters: []
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));