Skip to content

Commit 1e5c898

Browse files
committed
Refactor TableRenderer for support yield
1 parent de781d6 commit 1e5c898

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Yii2 multiple input change log
44
2.18.0 (in development)
55
=======================
66
- #246 accept `\Traversable` in model attribute for `yield` compatibility (bscheshirwork)
7+
- #250 accept `\Traversable` in TableRenderer for `yield` compatibility (bscheshirwork)
78

89
2.17.0
910
======

src/renderers/TableRenderer.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,16 @@ protected function renderBody()
170170
$rows = [];
171171

172172
if ($this->data) {
173-
$cnt = count($this->data);
174-
if ($this->min === $this->max && $cnt < $this->max) {
175-
$cnt = $this->max;
173+
$j = 0;
174+
foreach ($this->data as $index => $item) {
175+
if ($j++ <= $this->max) {
176+
$rows[] = $this->renderRowContent($index, $item);
177+
} else {
178+
break;
179+
}
176180
}
177-
178-
$indices = array_keys($this->data);
179-
180-
for ($i = 0; $i < $cnt; $i++) {
181-
$index = ArrayHelper::getValue($indices, $i, $i);
182-
$item = ArrayHelper::getValue($this->data, $index, null);
183-
$rows[] = $this->renderRowContent($index, $item);
181+
for ($i = $j; $i < $this->min; $i++) {
182+
$rows[] = $this->renderRowContent($i);
184183
}
185184
} elseif ($this->min > 0) {
186185
for ($i = 0; $i < $this->min; $i++) {

0 commit comments

Comments
 (0)