@@ -369,41 +369,59 @@ public function render()
369
369
370
370
$ this ->calculateNumberOfColumns ($ rows );
371
371
372
- $ rows = $ this ->buildTableRows ($ rows );
373
- $ this ->calculateColumnsWidth ($ rows );
372
+ $ rowGroups = $ this ->buildTableRows ($ rows );
373
+ $ this ->calculateColumnsWidth ($ rowGroups );
374
374
375
375
$ isHeader = !$ this ->horizontal ;
376
376
$ isFirstRow = $ this ->horizontal ;
377
377
$ hasTitle = (bool ) $ this ->headerTitle ;
378
- foreach ($ rows as $ row ) {
379
- if ($ divider === $ row ) {
380
- $ isHeader = false ;
381
- $ isFirstRow = true ;
382
378
383
- continue ;
384
- }
385
- if ($ row instanceof TableSeparator) {
386
- $ this ->renderRowSeparator ();
379
+ foreach ($ rowGroups as $ rowGroup ) {
380
+ $ isHeaderSeparatorRendered = false ;
387
381
388
- continue ;
389
- }
390
- if (!$ row ) {
391
- continue ;
392
- }
382
+ foreach ($ rowGroup as $ row ) {
383
+ if ($ divider === $ row ) {
384
+ $ isHeader = false ;
385
+ $ isFirstRow = true ;
393
386
394
- if ($ isHeader || $ isFirstRow ) {
395
- $ this ->renderRowSeparator (
396
- $ isHeader ? self ::SEPARATOR_TOP : self ::SEPARATOR_TOP_BOTTOM ,
397
- $ hasTitle ? $ this ->headerTitle : null ,
398
- $ hasTitle ? $ this ->style ->getHeaderTitleFormat () : null
399
- );
400
- $ isFirstRow = false ;
401
- $ hasTitle = false ;
402
- }
403
- if ($ this ->horizontal ) {
404
- $ this ->renderRow ($ row , $ this ->style ->getCellRowFormat (), $ this ->style ->getCellHeaderFormat ());
405
- } else {
406
- $ this ->renderRow ($ row , $ isHeader ? $ this ->style ->getCellHeaderFormat () : $ this ->style ->getCellRowFormat ());
387
+ continue ;
388
+ }
389
+
390
+ if ($ row instanceof TableSeparator) {
391
+ $ this ->renderRowSeparator ();
392
+
393
+ continue ;
394
+ }
395
+
396
+ if (!$ row ) {
397
+ continue ;
398
+ }
399
+
400
+ if ($ isHeader && !$ isHeaderSeparatorRendered ) {
401
+ $ this ->renderRowSeparator (
402
+ $ isHeader ? self ::SEPARATOR_TOP : self ::SEPARATOR_TOP_BOTTOM ,
403
+ $ hasTitle ? $ this ->headerTitle : null ,
404
+ $ hasTitle ? $ this ->style ->getHeaderTitleFormat () : null
405
+ );
406
+ $ hasTitle = false ;
407
+ $ isHeaderSeparatorRendered = true ;
408
+ }
409
+
410
+ if ($ isFirstRow ) {
411
+ $ this ->renderRowSeparator (
412
+ $ isHeader ? self ::SEPARATOR_TOP : self ::SEPARATOR_TOP_BOTTOM ,
413
+ $ hasTitle ? $ this ->headerTitle : null ,
414
+ $ hasTitle ? $ this ->style ->getHeaderTitleFormat () : null
415
+ );
416
+ $ isFirstRow = false ;
417
+ $ hasTitle = false ;
418
+ }
419
+
420
+ if ($ this ->horizontal ) {
421
+ $ this ->renderRow ($ row , $ this ->style ->getCellRowFormat (), $ this ->style ->getCellHeaderFormat ());
422
+ } else {
423
+ $ this ->renderRow ($ row , $ isHeader ? $ this ->style ->getCellHeaderFormat () : $ this ->style ->getCellRowFormat ());
424
+ }
407
425
}
408
426
}
409
427
$ this ->renderRowSeparator (self ::SEPARATOR_BOTTOM , $ this ->footerTitle , $ this ->style ->getFooterTitleFormat ());
@@ -587,13 +605,14 @@ private function buildTableRows(array $rows): TableRows
587
605
588
606
return new TableRows (function () use ($ rows , $ unmergedRows ): \Traversable {
589
607
foreach ($ rows as $ rowKey => $ row ) {
590
- yield $ row instanceof TableSeparator ? $ row : $ this ->fillCells ($ row );
608
+ $ rowGroup = [ $ row instanceof TableSeparator ? $ row : $ this ->fillCells ($ row )] ;
591
609
592
610
if (isset ($ unmergedRows [$ rowKey ])) {
593
611
foreach ($ unmergedRows [$ rowKey ] as $ row ) {
594
- yield $ row instanceof TableSeparator ? $ row : $ this ->fillCells ($ row );
612
+ $ rowGroup [] = $ row instanceof TableSeparator ? $ row : $ this ->fillCells ($ row );
595
613
}
596
614
}
615
+ yield $ rowGroup ;
597
616
}
598
617
});
599
618
}
@@ -734,14 +753,15 @@ private function getRowColumns(array $row): array
734
753
/**
735
754
* Calculates columns widths.
736
755
*/
737
- private function calculateColumnsWidth (iterable $ rows )
756
+ private function calculateColumnsWidth (iterable $ groups )
738
757
{
739
758
for ($ column = 0 ; $ column < $ this ->numberOfColumns ; ++$ column ) {
740
759
$ lengths = [];
741
- foreach ($ rows as $ row ) {
742
- if ($ row instanceof TableSeparator) {
743
- continue ;
744
- }
760
+ foreach ($ groups as $ group ) {
761
+ foreach ($ group as $ row ) {
762
+ if ($ row instanceof TableSeparator) {
763
+ continue ;
764
+ }
745
765
746
766
foreach ($ row as $ i => $ cell ) {
747
767
if ($ cell instanceof TableCell) {
@@ -756,7 +776,8 @@ private function calculateColumnsWidth(iterable $rows)
756
776
}
757
777
}
758
778
759
- $ lengths [] = $ this ->getCellWidth ($ row , $ column );
779
+ $ lengths [] = $ this ->getCellWidth ($ row , $ column );
780
+ }
760
781
}
761
782
762
783
$ this ->effectiveColumnWidths [$ column ] = max ($ lengths ) + Helper::strlen ($ this ->style ->getCellRowContentFormat ()) - 2 ;
0 commit comments