|
1 | 1 | import { Component, ViewChild, inject } from "@angular/core"; |
2 | 2 |
|
3 | | -import { IPivotConfiguration, IgxPivotDateDimension, IgxPivotNumericAggregate, PivotAggregation, IgxExcelExporterOptions, IgxExcelExporterService } from 'igniteui-angular/grids/core'; |
| 3 | +import { |
| 4 | + IPivotConfiguration, |
| 5 | + IgxPivotDateDimension, |
| 6 | + IgxPivotNumericAggregate, |
| 7 | + PivotAggregation, |
| 8 | + IgxExcelExporterOptions, |
| 9 | + IgxExcelExporterService, |
| 10 | + IgxPdfExporterService, |
| 11 | + IgxPdfExporterOptions, |
| 12 | + IColumnExportingEventArgs |
| 13 | +} from 'igniteui-angular/grids/core'; |
4 | 14 | import { IgxPivotGridComponent } from 'igniteui-angular/grids/pivot-grid'; |
5 | 15 | import { IgxButtonDirective } from 'igniteui-angular/directives'; |
6 | 16 | import { SALES_DATA } from "../../data/dataToAnalyze"; |
@@ -40,9 +50,10 @@ export class IgxTotalSaleAggregate { |
40 | 50 | }) |
41 | 51 | export class PivotExportComponent { |
42 | 52 | private excelExportService = inject(IgxExcelExporterService); |
| 53 | + private pdfExportService = inject(IgxPdfExporterService); |
43 | 54 |
|
44 | 55 | @ViewChild(IgxPivotGridComponent, { static: true }) public grid: IgxPivotGridComponent; |
45 | | - |
| 56 | + |
46 | 57 | public data = SALES_DATA; |
47 | 58 |
|
48 | 59 | public pivotConfig: IPivotConfiguration = { |
@@ -91,7 +102,7 @@ export class PivotExportComponent { |
91 | 102 | aggregator: IgxPivotNumericAggregate.sum, |
92 | 103 | label: 'Sum' |
93 | 104 | }], |
94 | | - enabled: true, |
| 105 | + enabled: false, |
95 | 106 | formatter: (value) => value ? '$' + parseFloat(value).toFixed(3) : undefined |
96 | 107 | }, |
97 | 108 | { |
@@ -124,4 +135,20 @@ export class PivotExportComponent { |
124 | 135 | public exportButtonHandler() { |
125 | 136 | this.excelExportService.export(this.grid, new IgxExcelExporterOptions('ExportedDataFile')); |
126 | 137 | } |
| 138 | + |
| 139 | + public exportPdfButtonHandler() { |
| 140 | + const pdfOptions = new IgxPdfExporterOptions('ExportedDataFile'); |
| 141 | + |
| 142 | + this.pdfExportService.columnExporting.subscribe((args: IColumnExportingEventArgs) => { |
| 143 | + const header = args.header || ''; |
| 144 | + |
| 145 | + // Cancel if it's a quarter (Q1-Q4) |
| 146 | + // This makes the PDF more readable by excluding less important columns |
| 147 | + if (/Q[1-4]/i.test(header)) { |
| 148 | + args.cancel = true; |
| 149 | + } |
| 150 | + }); |
| 151 | + |
| 152 | + this.pdfExportService.export(this.grid, pdfOptions); |
| 153 | + } |
127 | 154 | } |
0 commit comments