chg: [helpers:bootstrap] Improvements for table

pull/39/head
mokaddem 2021-02-23 11:42:26 +01:00
parent 2be8add320
commit 9a25d98c9a
1 changed files with 42 additions and 22 deletions

View File

@ -501,32 +501,52 @@ class BoostrapTable extends BootstrapGeneric {
],
]);
foreach ($this->items as $i => $row) {
$body .= $this->openNode('tr',[
'class' => [
!empty($row['_rowVariant']) ? "table-{$row['_rowVariant']}" : ''
]
]);
if (array_keys($row) !== range(0, count($row) - 1)) { // associative array
foreach ($this->fields as $i => $field) {
if (is_array($field)) {
$key = $field['key'];
} else {
$key = $field;
}
$cellValue = $row[$key];
$body .= $this->genNode('td', [], h($cellValue));
}
} else {
foreach ($row as $cellValue) {
$body .= $this->genNode('td', [], h($cellValue));
}
}
$body .= $this->closeNode('tr');;
$body .= $this->genRow($row);
}
$body .= $this->closeNode('tbody');;
$body .= $this->closeNode('tbody');
return $body;
}
private function genRow($row)
{
$html = $this->openNode('tr',[
'class' => [
!empty($row['_rowVariant']) ? "table-{$row['_rowVariant']}" : ''
]
]);
if (array_keys($row) !== range(0, count($row) - 1)) { // associative array
foreach ($this->fields as $i => $field) {
if (is_array($field)) {
$key = $field['key'];
} else {
$key = $field;
}
$cellValue = $row[$key];
$html .= $this->genCell($cellValue, $field, $row);
}
} else { // indexed array
foreach ($row as $cellValue) {
$html .= $this->genCell($cellValue, $field, $row);
}
}
$html .= $this->closeNode('tr');
return $html;
}
private function genCell($value, $field=[], $row=[])
{
if (isset($field['formatter'])) {
$cellContent = $field['formatter']($value, $row);
} else {
$cellContent = h($value);
}
return $this->genNode('td', [
'class' => [
!empty($row['_cellVariant']) ? "bg-{$row['_cellVariant']}" : ''
]
], $cellContent);
}
private function genCaption()
{
return $this->genNode('caption', [], h($this->caption));