Add option to hide columns
authorMarcel Werk <burntime@woltlab.com>
Tue, 5 Nov 2024 14:15:26 +0000 (15:15 +0100)
committerMarcel Werk <burntime@woltlab.com>
Tue, 5 Nov 2024 14:15:26 +0000 (15:15 +0100)
This is intended to enable filtering by columns that are not displayed.

com.woltlab.wcf/templates/shared_gridView.tpl
com.woltlab.wcf/templates/shared_gridViewRows.tpl
wcfsetup/install/files/lib/system/view/grid/AbstractGridView.class.php
wcfsetup/install/files/lib/system/view/grid/GridViewColumn.class.php

index f730807e87013f679d8982601a71f2f67ce5bf7a..1377dace36e81f193d00211bcbadbea749e4b1f4 100644 (file)
@@ -18,7 +18,7 @@
        <table class="gridView__table" id="{$view->getID()}_table"{if !$view->countRows()} hidden{/if}>
                <thead>
                        <tr class="gridView__headerRow">
-                               {foreach from=$view->getColumns() item='column'}
+                               {foreach from=$view->getVisibleColumns() item='column'}
                                        <th
                                                class="gridView__headerColumn {$column->getClasses()}"
                                                data-id="{$column->getID()}"
index e5304c7b33c99eaeb318e455b2b3e7fcc9465bbe..e51236c0a5458de3690b54e9d55ccc198fa5dd6b 100644 (file)
@@ -1,7 +1,7 @@
 
 {foreach from=$view->getRows() item='row'}
        <tr class="gridView__row" data-object-id="{$view->getObjectID($row)}">
-               {foreach from=$view->getColumns() item='column'}
+               {foreach from=$view->getVisibleColumns() item='column'}
                        <td class="gridView__column {$column->getClasses()}">
                                {unsafe:$view->renderColumn($column, $row)}
                        </td>
index 28265204e72d1004e7c93e4db1eb852042fec73d..b4056ff2a19c99b249335aa3c42654a6d76f3daf 100644 (file)
@@ -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) {
index cafa07d190db57847df0405e24217aabbd09106c..ea1199d9c2d3ed288b2a47367d206acb3baa9803 100644 (file)
@@ -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;
+    }
 }