Export table and chart into the same PDF document using toolbar
23 Aug 20255 minutes to read
By default, when the displayOption.view property is set to Both in the pivot table, the export functionality exports either the table or the chart to the PDF document based on the current value of the displayOption.primary property. However, to export both the table and the chart into the same PDF document simultaneously, use the pdfExport method during the actionBegin event.
This approach is particularly useful when users need comprehensive reports that include both tabular data and visual representations in a single document.
Implementation steps
Follow these steps to enable combined table and chart export:
- Configure the pivot view with both table and chart display options
- Handle the actionBegin event to intercept the default export action
-
Call the pdfExport method with the
exportBothTableAndChart
parameter set to true
Code example
The following example demonstrates how to restrict the built-in export action by setting the args.cancel option to true in the actionBegin event, and then export both the table and chart by calling the pdfExport method with the exportBothTableAndChart
argument set 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, 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';
import { DataSourceSettingsModel } from '@syncfusion/ej2-pivotview/src/model/datasourcesettings-model';
@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?: DataSourceSettingsModel;
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));