Skip to content

Commit 8e46d65

Browse files
Copilotkdinev
andcommitted
Add hierarchy visualization and schematic support for PDF export
- Added indentation support for TreeGrid and HierarchicalGrid records in PDF export - Records with level property now indent by 15pt per level in first column - Skip hidden records (collapsed hierarchy nodes) from export - Added jspdf to ng-add schematic dependencies map for automatic installation Co-authored-by: kdinev <[email protected]>
1 parent b98b3f8 commit 8e46d65

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

projects/igniteui-angular/schematics/utils/dependency-handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const schematicsPackage = '@igniteui/angular-schematics';
2121
export const DEPENDENCIES_MAP: PackageEntry[] = [
2222
// dependencies
2323
{ name: 'fflate', target: PackageTarget.REGULAR },
24+
{ name: 'jspdf', target: PackageTarget.REGULAR },
2425
{ name: 'tslib', target: PackageTarget.NONE },
2526
{ name: 'igniteui-trial-watermark', target: PackageTarget.NONE },
2627
{ name: 'lodash-es', target: PackageTarget.NONE },

projects/igniteui-angular/src/lib/services/pdf/pdf-exporter.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export class IgxPdfExporterService extends IgxBaseExporter {
8484
const columnWidth = usableWidth / columns.length;
8585
const rowHeight = 20;
8686
const headerHeight = 25;
87+
const indentSize = 15; // Indentation per level for hierarchical data
8788

8889
let yPosition = margin;
8990

@@ -120,12 +121,22 @@ export class IgxPdfExporterService extends IgxBaseExporter {
120121
pdf.setFont('helvetica', 'normal');
121122

122123
data.forEach((record) => {
124+
// Skip hidden records (collapsed hierarchy)
125+
if (record.hidden) {
126+
return;
127+
}
128+
123129
// Check if we need a new page
124130
if (yPosition + rowHeight > pageHeight - margin) {
125131
pdf.addPage();
126132
yPosition = margin;
127133
}
128134

135+
// Calculate indentation for hierarchical records
136+
const isHierarchical = record.type === 'TreeGridRecord' || record.type === 'HierarchicalGridRecord';
137+
const indentLevel = isHierarchical ? (record.level || 0) : 0;
138+
const indent = indentLevel * indentSize;
139+
129140
columns.forEach((col, index) => {
130141
const xPosition = margin + (index * columnWidth);
131142
let cellValue = record.data[col.field];
@@ -143,8 +154,11 @@ export class IgxPdfExporterService extends IgxBaseExporter {
143154
pdf.rect(xPosition, yPosition, columnWidth, rowHeight);
144155
}
145156

146-
// Truncate text if it's too long
147-
const maxTextWidth = columnWidth - 10;
157+
// Apply indentation to the first column for hierarchical data
158+
const textIndent = (index === 0 && isHierarchical) ? indent : 0;
159+
160+
// Truncate text if it's too long, accounting for indentation
161+
const maxTextWidth = columnWidth - 10 - textIndent;
148162
let displayText = cellValue;
149163

150164
if (pdf.getTextWidth(displayText) > maxTextWidth) {
@@ -155,7 +169,7 @@ export class IgxPdfExporterService extends IgxBaseExporter {
155169
}
156170

157171
const textY = yPosition + rowHeight / 2 + options.fontSize / 3;
158-
pdf.text(displayText, xPosition + 5, textY);
172+
pdf.text(displayText, xPosition + 5 + textIndent, textY);
159173
});
160174

161175
yPosition += rowHeight;

0 commit comments

Comments
 (0)