@@ -449,12 +449,17 @@ export class IgxPdfExporterService extends IgxBaseExporter {
449449 rowHeight : number ,
450450 options : IgxPdfExporterOptions
451451 ) : number {
452- // Get columns for this child owner (owner is the island object)
453- // Exclude GRID_LEVEL_COL from child columns
454- const childColumns = this . _ownersMap . get ( childOwner ) ?. columns . filter (
455- col => col . field && col . field !== GRID_LEVEL_COL && ! col . skip && col . headerType === ExportHeaderType . ColumnHeader
452+ // Get columns for this child owner
453+ const childOwnerObj = this . _ownersMap . get ( childOwner ) ;
454+
455+ const allChildColumns = childOwnerObj ?. columns . filter (
456+ col => col . field !== GRID_LEVEL_COL && ! col . skip
456457 ) || [ ] ;
457458
459+ const childColumns = allChildColumns . filter (
460+ col => col . headerType === ExportHeaderType . ColumnHeader
461+ ) ;
462+
458463 if ( childColumns . length === 0 ) {
459464 return yPosition ;
460465 }
@@ -469,9 +474,36 @@ export class IgxPdfExporterService extends IgxBaseExporter {
469474 // Add some spacing before child table
470475 yPosition += 5 ;
471476
472- // Draw child table with indentation
473- const childTableWidth = usableWidth - indentPerLevel ;
474- const childColumnWidth = childTableWidth / childColumns . length ;
477+ // Calculate available width after indentation
478+ const availableWidth = usableWidth - indentPerLevel ;
479+
480+ // Calculate total column span for proper width distribution
481+ const maxLevel = childOwnerObj ?. maxLevel || 0 ;
482+
483+ // Fix startIndex for all child columns
484+ let currentIndex = 0 ;
485+ for ( const col of allChildColumns ) {
486+ debugger
487+ if ( col . level === 0 && ( col . headerType === ExportHeaderType . MultiColumnHeader || col . headerType === ExportHeaderType . ColumnHeader ) ) {
488+ col . startIndex = currentIndex ;
489+ currentIndex += col . columnSpan || 1 ;
490+ }
491+ }
492+
493+ let totalColumnSpan = 0 ;
494+ if ( maxLevel > 0 ) {
495+ const baseLevelColumns = allChildColumns . filter ( col =>
496+ col . level === 0 &&
497+ ( col . headerType === ExportHeaderType . MultiColumnHeader || col . headerType === ExportHeaderType . ColumnHeader )
498+ ) ;
499+ totalColumnSpan = baseLevelColumns . reduce ( ( sum , col ) => sum + ( col . columnSpan || 1 ) , 0 ) ;
500+ } else {
501+ totalColumnSpan = childColumns . length ;
502+ }
503+
504+ // Recalculate column width based on child's column count and available width
505+ const childColumnWidth = availableWidth / totalColumnSpan ;
506+ const actualChildTableWidth = childColumnWidth * totalColumnSpan ;
475507 const childTableX = margin + indentPerLevel ;
476508
477509 // Check if we need a new page for headers
@@ -481,25 +513,24 @@ export class IgxPdfExporterService extends IgxBaseExporter {
481513 }
482514
483515 // Draw child table headers
484- const childOwnerObj = this . _ownersMap . get ( childOwner ) ;
485- const hasMultiColumnHeaders = childOwnerObj ?. maxLevel > 0 && childOwnerObj . columns . some ( col => col . headerType === ExportHeaderType . MultiColumnHeader ) ;
516+ const hasMultiColumnHeaders = maxLevel > 0 && childOwnerObj . columns . some ( col => col . headerType === ExportHeaderType . MultiColumnHeader ) ;
486517
487518 if ( hasMultiColumnHeaders ) {
488519 yPosition = this . drawMultiLevelHeaders (
489520 pdf ,
490- childOwnerObj . columns ,
521+ allChildColumns ,
491522 [ ] , // rowDimensionHeaders, if any
492- childOwnerObj . maxLevel ,
523+ maxLevel ,
493524 0 , // maxRowLevel
494525 childTableX ,
495526 yPosition ,
496527 childColumnWidth ,
497528 headerHeight ,
498- childTableWidth ,
529+ actualChildTableWidth ,
499530 options
500531 ) ;
501532 } else {
502- this . drawTableHeaders ( pdf , childColumns , [ ] , childTableX , yPosition , childColumnWidth , headerHeight , childTableWidth , options ) ;
533+ this . drawTableHeaders ( pdf , childColumns , [ ] , childTableX , yPosition , childColumnWidth , headerHeight , actualChildTableWidth , options ) ;
503534 yPosition += headerHeight ;
504535 }
505536
@@ -515,8 +546,16 @@ export class IgxPdfExporterService extends IgxBaseExporter {
515546 pdf . addPage ( ) ;
516547 yPosition = margin ;
517548 // Redraw headers on new page
518- this . drawTableHeaders ( pdf , childColumns , [ ] , childTableX , yPosition , childColumnWidth , headerHeight , childTableWidth , options ) ;
519- yPosition += headerHeight ;
549+ if ( hasMultiColumnHeaders ) {
550+ yPosition = this . drawMultiLevelHeaders (
551+ pdf , allChildColumns , [ ] , maxLevel , 0 ,
552+ childTableX , yPosition , childColumnWidth , headerHeight ,
553+ actualChildTableWidth , options
554+ ) ;
555+ } else {
556+ this . drawTableHeaders ( pdf , childColumns , [ ] , childTableX , yPosition , childColumnWidth , headerHeight , actualChildTableWidth , options ) ;
557+ yPosition += headerHeight ;
558+ }
520559 }
521560
522561 // Draw the child record
@@ -555,7 +594,7 @@ export class IgxPdfExporterService extends IgxBaseExporter {
555594 gcOwner ,
556595 yPosition ,
557596 margin ,
558- indentPerLevel + 30 , // Increase indentation for next level
597+ indentPerLevel + 20 , // Increase indentation for next level
559598 usableWidth ,
560599 pageHeight ,
561600 headerHeight ,
0 commit comments