Skip to content

Commit f1c6832

Browse files
Copilotkdinev
andcommitted
Fix hierarchical grid to render nested child tables correctly
Fixed issue where grandchildren (child tables of child tables) were being rendered as regular rows instead of separate nested tables. Changes: - Moved grandchildren detection logic before drawing the parent row - If a child record has grandchildren, draw it as a parent row first, then recursively render its children as a nested child table - If a child record has no grandchildren, draw it as a regular row - This ensures proper nested table structure at all levels - Each level of nesting gets its own child table with headers Now hierarchical grids correctly render child tables at all nesting levels, with proper indentation and table structure maintained throughout. Co-authored-by: kdinev <[email protected]>
1 parent 5b0e25d commit f1c6832

File tree

1 file changed

+46
-30
lines changed

1 file changed

+46
-30
lines changed

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

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -324,24 +324,13 @@ export class IgxPdfExporterService extends IgxBaseExporter {
324324
while (childIndex < childRecords.length) {
325325
const childRecord = childRecords[childIndex];
326326

327-
// Check if we need a new page
328-
if (yPosition + rowHeight > pageHeight - margin) {
329-
pdf.addPage();
330-
yPosition = margin;
331-
// Redraw headers on new page
332-
this.drawTableHeaders(pdf, childColumns, childTableX, yPosition, childColumnWidth, headerHeight, childTableWidth, options);
333-
yPosition += headerHeight;
334-
}
335-
336-
this.drawDataRow(pdf, childRecord, childColumns, childTableX, yPosition, childColumnWidth, rowHeight, 0, options);
337-
yPosition += rowHeight;
338-
339327
// Check if this child record has its own children (next level in hierarchy)
340328
const childRecordIndex = allData.indexOf(childRecord);
329+
const grandchildRecords: IExportRecord[] = [];
330+
let grandchildOwner: string | null = null;
331+
341332
if (childRecordIndex >= 0 && childRecordIndex + 1 < allData.length) {
342333
// Look for grandchildren
343-
const grandchildRecords: IExportRecord[] = [];
344-
let grandchildOwner: string | null = null;
345334
let k = childRecordIndex + 1;
346335

347336
// Collect all grandchildren that belong to this child
@@ -355,24 +344,51 @@ export class IgxPdfExporterService extends IgxBaseExporter {
355344
}
356345
k++;
357346
}
347+
}
358348

359-
// Recursively draw grandchildren if they exist
360-
if (grandchildRecords.length > 0 && grandchildOwner) {
361-
yPosition = this.drawHierarchicalChildren(
362-
pdf,
363-
allData,
364-
grandchildRecords,
365-
grandchildOwner,
366-
yPosition,
367-
margin,
368-
indentPerLevel + 30, // Increase indentation for next level
369-
usableWidth,
370-
pageHeight,
371-
headerHeight,
372-
rowHeight,
373-
options
374-
);
349+
// If this child has grandchildren, render them as a nested child table
350+
if (grandchildRecords.length > 0 && grandchildOwner) {
351+
// Check if we need a new page for parent row
352+
if (yPosition + rowHeight > pageHeight - margin) {
353+
pdf.addPage();
354+
yPosition = margin;
355+
// Redraw headers on new page
356+
this.drawTableHeaders(pdf, childColumns, childTableX, yPosition, childColumnWidth, headerHeight, childTableWidth, options);
357+
yPosition += headerHeight;
358+
}
359+
360+
// Draw the parent row (child record)
361+
this.drawDataRow(pdf, childRecord, childColumns, childTableX, yPosition, childColumnWidth, rowHeight, 0, options);
362+
yPosition += rowHeight;
363+
364+
// Recursively draw grandchildren as a nested child table
365+
yPosition = this.drawHierarchicalChildren(
366+
pdf,
367+
allData,
368+
grandchildRecords,
369+
grandchildOwner,
370+
yPosition,
371+
margin,
372+
indentPerLevel + 30, // Increase indentation for next level
373+
usableWidth,
374+
pageHeight,
375+
headerHeight,
376+
rowHeight,
377+
options
378+
);
379+
} else {
380+
// No grandchildren, just draw this child as a regular row
381+
// Check if we need a new page
382+
if (yPosition + rowHeight > pageHeight - margin) {
383+
pdf.addPage();
384+
yPosition = margin;
385+
// Redraw headers on new page
386+
this.drawTableHeaders(pdf, childColumns, childTableX, yPosition, childColumnWidth, headerHeight, childTableWidth, options);
387+
yPosition += headerHeight;
375388
}
389+
390+
this.drawDataRow(pdf, childRecord, childColumns, childTableX, yPosition, childColumnWidth, rowHeight, 0, options);
391+
yPosition += rowHeight;
376392
}
377393

378394
childIndex++;

0 commit comments

Comments
 (0)