Skip to content

Commit 59b8b00

Browse files
authored
Add pdf export button (#3836)
1 parent f2dcc0b commit 59b8b00

3 files changed

Lines changed: 41 additions & 6 deletions

File tree

src/app/pivot-grid/pivot-export/pivot-export.component.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<div class="pivotgrid-sample">
22
<div class="button-container">
3-
<button igxButton="contained" (click)="exportButtonHandler()">Export To Excel</button>
4-
Press the button to export the Pivot Grid as .xlsx file.
3+
<div class="button-container__actions">
4+
<button igxButton="contained" (click)="exportButtonHandler()">Export To Excel</button>
5+
<button igxButton="contained" (click)="exportPdfButtonHandler()">Export To PDF</button>
6+
</div>
57
</div>
68

79
<igx-pivot-grid #grid [data]="data" [pivotConfiguration]="pivotConfig" [rowSelection]="'single'"

src/app/pivot-grid/pivot-export/pivot-export.component.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
height: 80%;
66

77
.button-container {
8-
align-items: flex-start;
98
margin: 25px auto;
9+
10+
&__actions {
11+
display: flex;
12+
flex-direction: row;
13+
gap: 16px;
14+
align-items: center;
15+
}
1016
}
1117

1218
igx-pivot-grid {

src/app/pivot-grid/pivot-export/pivot-export.component.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { Component, ViewChild, inject } from "@angular/core";
22

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';
414
import { IgxPivotGridComponent } from 'igniteui-angular/grids/pivot-grid';
515
import { IgxButtonDirective } from 'igniteui-angular/directives';
616
import { SALES_DATA } from "../../data/dataToAnalyze";
@@ -40,9 +50,10 @@ export class IgxTotalSaleAggregate {
4050
})
4151
export class PivotExportComponent {
4252
private excelExportService = inject(IgxExcelExporterService);
53+
private pdfExportService = inject(IgxPdfExporterService);
4354

4455
@ViewChild(IgxPivotGridComponent, { static: true }) public grid: IgxPivotGridComponent;
45-
56+
4657
public data = SALES_DATA;
4758

4859
public pivotConfig: IPivotConfiguration = {
@@ -91,7 +102,7 @@ export class PivotExportComponent {
91102
aggregator: IgxPivotNumericAggregate.sum,
92103
label: 'Sum'
93104
}],
94-
enabled: true,
105+
enabled: false,
95106
formatter: (value) => value ? '$' + parseFloat(value).toFixed(3) : undefined
96107
},
97108
{
@@ -124,4 +135,20 @@ export class PivotExportComponent {
124135
public exportButtonHandler() {
125136
this.excelExportService.export(this.grid, new IgxExcelExporterOptions('ExportedDataFile'));
126137
}
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+
}
127154
}

0 commit comments

Comments
 (0)