Skip to content

Commit 6658762

Browse files
Copilotkdinev
andcommitted
Fix hierarchical grid export to handle multiple child islands per record
Fixed issue where each record could have multiple child islands (different owners) but only one was being rendered. The code now: - Groups grandchildren by their owner (each owner represents a different child island) - Renders a separate nested child table for each island/owner - Maintains proper recursive structure for unlimited nesting depth - Each island gets its own headers and proper indentation This ensures that hierarchical grids with multiple child grids per parent row export correctly, with all child islands rendered as separate nested tables. Co-authored-by: kdinev <[email protected]>
1 parent f1c6832 commit 6658762

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

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

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -326,28 +326,28 @@ export class IgxPdfExporterService extends IgxBaseExporter {
326326

327327
// Check if this child record has its own children (next level in hierarchy)
328328
const childRecordIndex = allData.indexOf(childRecord);
329-
const grandchildRecords: IExportRecord[] = [];
330-
let grandchildOwner: string | null = null;
329+
const grandchildrenByOwner = new Map<string, IExportRecord[]>();
331330

332331
if (childRecordIndex >= 0 && childRecordIndex + 1 < allData.length) {
333-
// Look for grandchildren
332+
// Look for grandchildren and group them by owner (each owner represents a different child island)
334333
let k = childRecordIndex + 1;
335334

336-
// Collect all grandchildren that belong to this child
335+
// Collect all grandchildren that belong to this child, grouped by owner
337336
while (k < allData.length && allData[k].level > childRecord.level) {
338337
// Only include direct children (next level)
339338
if (allData[k].level === childRecord.level + 1 && !allData[k].hidden) {
340-
grandchildRecords.push(allData[k]);
341-
if (!grandchildOwner) {
342-
grandchildOwner = allData[k].owner.toString();
339+
const owner = allData[k].owner.toString();
340+
if (!grandchildrenByOwner.has(owner)) {
341+
grandchildrenByOwner.set(owner, []);
343342
}
343+
grandchildrenByOwner.get(owner)!.push(allData[k]);
344344
}
345345
k++;
346346
}
347347
}
348348

349-
// If this child has grandchildren, render them as a nested child table
350-
if (grandchildRecords.length > 0 && grandchildOwner) {
349+
// If this child has grandchildren, render them as nested child tables (one per owner/island)
350+
if (grandchildrenByOwner.size > 0) {
351351
// Check if we need a new page for parent row
352352
if (yPosition + rowHeight > pageHeight - margin) {
353353
pdf.addPage();
@@ -361,21 +361,23 @@ export class IgxPdfExporterService extends IgxBaseExporter {
361361
this.drawDataRow(pdf, childRecord, childColumns, childTableX, yPosition, childColumnWidth, rowHeight, 0, options);
362362
yPosition += rowHeight;
363363

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-
);
364+
// Recursively draw each island's grandchildren as a separate nested child table
365+
for (const [grandchildOwner, grandchildRecords] of grandchildrenByOwner) {
366+
yPosition = this.drawHierarchicalChildren(
367+
pdf,
368+
allData,
369+
grandchildRecords,
370+
grandchildOwner,
371+
yPosition,
372+
margin,
373+
indentPerLevel + 30, // Increase indentation for next level
374+
usableWidth,
375+
pageHeight,
376+
headerHeight,
377+
rowHeight,
378+
options
379+
);
380+
}
379381
} else {
380382
// No grandchildren, just draw this child as a regular row
381383
// Check if we need a new page

0 commit comments

Comments
 (0)