diff --git a/config/widgets-themes.php b/config/widgets-themes.php index 435116f74..00d3e2b4b 100644 --- a/config/widgets-themes.php +++ b/config/widgets-themes.php @@ -19,6 +19,7 @@ 'sortableHeaderPrepend()' => ['
'], 'sortableHeaderAscPrepend()' => ['
'], 'sortableHeaderDescPrepend()' => ['
'], + 'filterCellAttributes()' => [['class' => 'align-top']], 'addColumnRendererConfigs()' => [ [ ActionColumnRenderer::class => [ diff --git a/src/GridView.php b/src/GridView.php index 878de3d12..9cac3ac11 100644 --- a/src/GridView.php +++ b/src/GridView.php @@ -77,6 +77,8 @@ final class GridView extends BaseListView private ?string $sortableLinkAscClass = null; private ?string $sortableLinkDescClass = null; + private array $filterCellAttributes = []; + private RendererContainer $columnRendererContainer; /** @@ -102,6 +104,18 @@ public function addColumnRendererConfigs(array $configs): self return $new; } + /** + * Return new instance with the HTML attributes for the filter cell (`td`) tag. + * + * @param array $attributes The tag attributes in terms of name-value pairs. + */ + public function filterCellAttributes(array $attributes): self + { + $new = clone $this; + $new->filterCellAttributes = $attributes; + return $new; + } + public function enableMultiSort(bool $value = true): self { $new = clone $this; @@ -446,7 +460,7 @@ protected function renderItems(array $items, ValidationResult $filterValidationR ); foreach ($columns as $i => $column) { $cell = $renderers[$i] instanceof FilterableColumnRendererInterface - ? $renderers[$i]->renderFilter($column, new Cell(), $filterContext) + ? $renderers[$i]->renderFilter($column, new Cell(attributes: $this->filterCellAttributes), $filterContext) : null; if ($cell === null) { $tags[] = Html::td(' ')->encode(false);