@@ -383,41 +383,59 @@ public function render()
383
383
384
384
$ this ->calculateNumberOfColumns ($ rows );
385
385
386
- $ rows = $ this ->buildTableRows ($ rows );
387
- $ this ->calculateColumnsWidth ($ rows );
386
+ $ rowGroups = $ this ->buildTableRows ($ rows );
387
+ $ this ->calculateColumnsWidth ($ rowGroups );
388
388
389
389
$ isHeader = !$ this ->horizontal ;
390
390
$ isFirstRow = $ this ->horizontal ;
391
391
$ hasTitle = (bool ) $ this ->headerTitle ;
392
- foreach ($ rows as $ row ) {
393
- if ($ divider === $ row ) {
394
- $ isHeader = false ;
395
- $ isFirstRow = true ;
396
392
397
- continue ;
398
- }
399
- if ($ row instanceof TableSeparator) {
400
- $ this ->renderRowSeparator ();
393
+ foreach ($ rowGroups as $ rowGroup ) {
394
+ $ isHeaderSeparatorRendered = false ;
401
395
402
- continue ;
403
- }
404
- if (!$ row ) {
405
- continue ;
406
- }
396
+ foreach ($ rowGroup as $ row ) {
397
+ if ($ divider === $ row ) {
398
+ $ isHeader = false ;
399
+ $ isFirstRow = true ;
407
400
408
- if ($ isHeader || $ isFirstRow ) {
409
- $ this ->renderRowSeparator (
410
- $ isHeader ? self ::SEPARATOR_TOP : self ::SEPARATOR_TOP_BOTTOM ,
411
- $ hasTitle ? $ this ->headerTitle : null ,
412
- $ hasTitle ? $ this ->style ->getHeaderTitleFormat () : null
413
- );
414
- $ isFirstRow = false ;
415
- $ hasTitle = false ;
416
- }
417
- if ($ this ->horizontal ) {
418
- $ this ->renderRow ($ row , $ this ->style ->getCellRowFormat (), $ this ->style ->getCellHeaderFormat ());
419
- } else {
420
- $ this ->renderRow ($ row , $ isHeader ? $ this ->style ->getCellHeaderFormat () : $ this ->style ->getCellRowFormat ());
401
+ continue ;
402
+ }
403
+
404
+ if ($ row instanceof TableSeparator) {
405
+ $ this ->renderRowSeparator ();
406
+
407
+ continue ;
408
+ }
409
+
410
+ if (!$ row ) {
411
+ continue ;
412
+ }
413
+
414
+ if ($ isHeader && !$ isHeaderSeparatorRendered ) {
415
+ $ this ->renderRowSeparator (
416
+ $ isHeader ? self ::SEPARATOR_TOP : self ::SEPARATOR_TOP_BOTTOM ,
417
+ $ hasTitle ? $ this ->headerTitle : null ,
418
+ $ hasTitle ? $ this ->style ->getHeaderTitleFormat () : null
419
+ );
420
+ $ hasTitle = false ;
421
+ $ isHeaderSeparatorRendered = true ;
422
+ }
423
+
424
+ if ($ isFirstRow ) {
425
+ $ this ->renderRowSeparator (
426
+ $ isHeader ? self ::SEPARATOR_TOP : self ::SEPARATOR_TOP_BOTTOM ,
427
+ $ hasTitle ? $ this ->headerTitle : null ,
428
+ $ hasTitle ? $ this ->style ->getHeaderTitleFormat () : null
429
+ );
430
+ $ isFirstRow = false ;
431
+ $ hasTitle = false ;
432
+ }
433
+
434
+ if ($ this ->horizontal ) {
435
+ $ this ->renderRow ($ row , $ this ->style ->getCellRowFormat (), $ this ->style ->getCellHeaderFormat ());
436
+ } else {
437
+ $ this ->renderRow ($ row , $ isHeader ? $ this ->style ->getCellHeaderFormat () : $ this ->style ->getCellRowFormat ());
438
+ }
421
439
}
422
440
}
423
441
$ this ->renderRowSeparator (self ::SEPARATOR_BOTTOM , $ this ->footerTitle , $ this ->style ->getFooterTitleFormat ());
@@ -624,13 +642,14 @@ private function buildTableRows(array $rows): TableRows
624
642
625
643
return new TableRows (function () use ($ rows , $ unmergedRows ): \Traversable {
626
644
foreach ($ rows as $ rowKey => $ row ) {
627
- yield $ row instanceof TableSeparator ? $ row : $ this ->fillCells ($ row );
645
+ $ rowGroup = [ $ row instanceof TableSeparator ? $ row : $ this ->fillCells ($ row )] ;
628
646
629
647
if (isset ($ unmergedRows [$ rowKey ])) {
630
648
foreach ($ unmergedRows [$ rowKey ] as $ row ) {
631
- yield $ row instanceof TableSeparator ? $ row : $ this ->fillCells ($ row );
649
+ $ rowGroup [] = $ row instanceof TableSeparator ? $ row : $ this ->fillCells ($ row );
632
650
}
633
651
}
652
+ yield $ rowGroup ;
634
653
}
635
654
});
636
655
}
@@ -771,14 +790,15 @@ private function getRowColumns(array $row): array
771
790
/**
772
791
* Calculates columns widths.
773
792
*/
774
- private function calculateColumnsWidth (iterable $ rows )
793
+ private function calculateColumnsWidth (iterable $ groups )
775
794
{
776
795
for ($ column = 0 ; $ column < $ this ->numberOfColumns ; ++$ column ) {
777
796
$ lengths = [];
778
- foreach ($ rows as $ row ) {
779
- if ($ row instanceof TableSeparator) {
780
- continue ;
781
- }
797
+ foreach ($ groups as $ group ) {
798
+ foreach ($ group as $ row ) {
799
+ if ($ row instanceof TableSeparator) {
800
+ continue ;
801
+ }
782
802
783
803
foreach ($ row as $ i => $ cell ) {
784
804
if ($ cell instanceof TableCell) {
@@ -793,7 +813,8 @@ private function calculateColumnsWidth(iterable $rows)
793
813
}
794
814
}
795
815
796
- $ lengths [] = $ this ->getCellWidth ($ row , $ column );
816
+ $ lengths [] = $ this ->getCellWidth ($ row , $ column );
817
+ }
797
818
}
798
819
799
820
$ this ->effectiveColumnWidths [$ column ] = max ($ lengths ) + Helper::width ($ this ->style ->getCellRowContentFormat ()) - 2 ;
0 commit comments