fix: [helpers:bootstrap] Table's cell generator gets the correct row index

pull/85/head
Sami Mokaddem 2022-01-17 15:22:52 +01:00
parent f18307b3cb
commit 1c81257b75
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
1 changed files with 7 additions and 7 deletions

View File

@ -637,13 +637,13 @@ class BoostrapTable extends BootstrapGeneric {
],
]);
foreach ($this->items as $i => $row) {
$body .= $this->genRow($row);
$body .= $this->genRow($row, $i);
}
$body .= $this->closeNode('tbody');
return $body;
}
private function genRow($row)
private function genRow($row, $rowIndex)
{
$html = $this->openNode('tr',[
'class' => [
@ -658,21 +658,21 @@ class BoostrapTable extends BootstrapGeneric {
$key = $field;
}
$cellValue = Hash::get($row, $key);
$html .= $this->genCell($cellValue, $field, $row, $i);
$html .= $this->genCell($cellValue, $field, $row, $rowIndex);
}
} else { // indexed array
foreach ($row as $cellValue) {
$html .= $this->genCell($cellValue, $field, $row, $i);
foreach ($row as $i => $cellValue) {
$html .= $this->genCell($cellValue, 'index', $row, $rowIndex);
}
}
$html .= $this->closeNode('tr');
return $html;
}
private function genCell($value, $field=[], $row=[], $i=0)
private function genCell($value, $field=[], $row=[], $rowIndex=0)
{
if (isset($field['formatter'])) {
$cellContent = $field['formatter']($value, $row, $i);
$cellContent = $field['formatter']($value, $row, $rowIndex);
} else if (isset($field['element'])) {
$cellContent = $this->btHelper->getView()->element($field['element'], [
'data' => [$value],