From 15a2b1ce08125bec69c8b66dc798309017f45cc7 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 5 Nov 2024 15:15:26 +0100 Subject: [PATCH] Add option to hide columns This is intended to enable filtering by columns that are not displayed. --- com.woltlab.wcf/templates/shared_gridView.tpl | 2 +- com.woltlab.wcf/templates/shared_gridViewRows.tpl | 2 +- .../lib/system/view/grid/AbstractGridView.class.php | 8 ++++++++ .../lib/system/view/grid/GridViewColumn.class.php | 13 +++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) 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; + } } -- 2.20.1
getRows() item='row'}
{unsafe:$view->renderColumn($column, $row)}