From: Marcel Werk Date: Tue, 5 Nov 2024 14:15:26 +0000 (+0100) Subject: Add option to hide columns X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=15a2b1ce08125bec69c8b66dc798309017f45cc7;p=GitHub%2FWoltLab%2FWCF.git Add option to hide columns This is intended to enable filtering by columns that are not displayed. --- diff --git a/com.woltlab.wcf/templates/shared_gridView.tpl b/com.woltlab.wcf/templates/shared_gridView.tpl index f730807e87..1377dace36 100644 --- a/com.woltlab.wcf/templates/shared_gridView.tpl +++ b/com.woltlab.wcf/templates/shared_gridView.tpl @@ -18,7 +18,7 @@ countRows()} hidden{/if}> - {foreach from=$view->getColumns() item='column'} + {foreach from=$view->getVisibleColumns() item='column'} - {foreach from=$view->getColumns() item='column'} + {foreach from=$view->getVisibleColumns() item='column'} diff --git a/wcfsetup/install/files/lib/system/view/grid/AbstractGridView.class.php b/wcfsetup/install/files/lib/system/view/grid/AbstractGridView.class.php index 28265204e7..b4056ff2a1 100644 --- a/wcfsetup/install/files/lib/system/view/grid/AbstractGridView.class.php +++ b/wcfsetup/install/files/lib/system/view/grid/AbstractGridView.class.php @@ -58,6 +58,14 @@ abstract class AbstractGridView return $this->columns; } + /** + * @return GridViewColumn[] + */ + public function getVisibleColumns(): array + { + return \array_filter($this->getColumns(), fn($column) => !$column->isHidden()); + } + public function getColumn(string $id): ?GridViewColumn { foreach ($this->getColumns() as $column) { diff --git a/wcfsetup/install/files/lib/system/view/grid/GridViewColumn.class.php b/wcfsetup/install/files/lib/system/view/grid/GridViewColumn.class.php index cafa07d190..ea1199d9c2 100644 --- a/wcfsetup/install/files/lib/system/view/grid/GridViewColumn.class.php +++ b/wcfsetup/install/files/lib/system/view/grid/GridViewColumn.class.php @@ -20,6 +20,7 @@ final class GridViewColumn private bool $sortable = false; private string $sortById = ''; private ?IGridViewFilter $filter = null; + private bool $hidden = false; private function __construct(private readonly string $id) {} @@ -158,4 +159,16 @@ final class GridViewColumn return false; } + + public function hidden(bool $hidden = true): static + { + $this->hidden = $hidden; + + return $this; + } + + public function isHidden(): bool + { + return $this->hidden; + } }
getRows() item='row'}
{unsafe:$view->renderColumn($column, $row)}