public function grid()
{
return _class('html')->grid([
[
['s1'],
['s1'],
['s1'],
['s1'],
['s1'],
['s1'],
['s1'],
['s1', 'class' => 'btn btn-warning'],
['s1'],
['s1', 'class' => 'btn btn-primary'],
['s1'],
['s1'],
],
[
['s4'],
['s4'],
['s4'],
],
[
['s4', 'col' => 4, 'class' => 'alert alert-error'],
['s8', 'col' => 8, 'class' => 'alert alert-info'],
],
[
['s6'],
['s6'],
],
[
['s12'],
],
]);
}
public function grid($data = [], $extra = [])
{
if ($this->_is_bs5) {
return $this->_bs5()->grid($data, $extra);
}
$extra['id'] = ($extra['id'] ?? null) ?: __FUNCTION__ . '_' . ($this->_ids[__FUNCTION__] = ($this->_ids[__FUNCTION__] ?? 0) + 1);
$rows = [];
$ul_opened = false;
foreach ((array) $data as $id => $row) {
$items = [];
$row_col = count((array) $row) ? floor(12 / count((array) $row)) : 1;
if ($row_col < 1) {
$row_col = 1;
}
foreach ((array) $row as $rid => $item) {
// a plain string cell is the body, not an array of characters
$item = is_array($item) ? $item : [$item];
$body = ($item[0] ?? null) ?: ($item['body'] ?? null);
$col = ($item[1] ?? null) ?: ($item['col'] ?? null);
$class = ($item['class'] ?? null);
if ( ! $col) {
$col = $row_col;
}
$items[] = '<div class="span' . $col . ' col-md-' . $col . ($class ? ' ' . $class : '') . '">' . $body . '</div>';
}
$rows[] = '<div class="row-fluid show-grid">' . implode(PHP_EOL, $items) . '</div>';
}
return '<div class="grid' . (($extra['class'] ?? null) ? ' ' . ($extra['class'] ?? null) : '') . '" id="' . ($extra['id'] ?? null) . '">' . implode(PHP_EOL, (array) $rows) . '</div>';
}