<table class="table" id="{$view->getID()}_table">
<thead>
<tr>
- {unsafe:$view->renderHeader()}
+ {foreach from=$view->getColumns() item='column'}
+ <th
+ class="{$column->getClasses()}"
+ data-id="{$column->getID()}"
+ data-sortable="{$column->isSortable()}"
+ >
+ {unsafe:$column->getLabel()}
+ </th>
+ {/foreach}
</td>
</thead>
<tbody>
--- /dev/null
+
+{foreach from=$view->getRows() item='row'}
+ <tr>
+ {foreach from=$view->getColumns() item='column'}
+ <td class="{$column->getClasses()}">
+ {unsafe:$view->renderColumn($column, $row)}
+ </td>
+ {/foreach}
+ </tr>
+{/foreach}
return WCF::getTPL()->fetch('shared_gridView', 'wcf', ['view' => $this], true);
}
- public function renderHeader(): string
- {
- $header = '';
-
- foreach ($this->getColumns() as $column) {
- $header .= <<<EOT
- <th
- class="{$column->getClasses()}"
- data-id="{$column->getID()}"
- data-sortable="{$column->isSortable()}"
- >{$column->getLabel()}</th>
- EOT;
- }
-
- return $header;
- }
-
public function renderRows(): string
{
- $result = '';
-
- foreach ($this->getRows() as $row) {
- $result .= <<<EOT
- <tr>
- EOT;
-
- foreach ($this->getColumns() as $column) {
- $result .= <<<EOT
- <td class="{$column->getClasses()}">
- {$column->render($this->getData($row,$column->getID()),$row)}
- </td>
- EOT;
- }
-
- $result .= <<<EOT
- </tr>
- EOT;
- }
+ return WCF::getTPL()->fetch('shared_gridViewRows', 'wcf', ['view' => $this], true);
+ }
- return $result;
+ public function renderColumn(GridViewColumn $column, mixed $row): string
+ {
+ return $column->render($this->getData($row, $column->getID()), $row);
}
protected function getData(mixed $row, string $identifer): mixed
return $row[$identifer] ?? '';
}
- protected abstract function getRows(): array;
+ public abstract function getRows(): array;
public abstract function countRows(): int;