Skip to content

Commit

Permalink
Add filter cell attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Feb 20, 2024
1 parent 6254003 commit 1c80830
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/widgets-themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'sortableHeaderPrepend()' => ['<div class="float-end text-secondary text-opacity-50">⭥</div>'],
'sortableHeaderAscPrepend()' => ['<div class="float-end fw-bold">⭡</div>'],
'sortableHeaderDescPrepend()' => ['<div class="float-end fw-bold">⭣</div>'],
'filterCellAttributes()' => [['class' => 'align-top']],
'addColumnRendererConfigs()' => [
[
ActionColumnRenderer::class => [
Expand Down
16 changes: 15 additions & 1 deletion src/GridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ final class GridView extends BaseListView
private ?string $sortableLinkAscClass = null;
private ?string $sortableLinkDescClass = null;

private array $filterCellAttributes = [];

private RendererContainer $columnRendererContainer;

/**
Expand All @@ -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;
Expand Down Expand Up @@ -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('&nbsp;')->encode(false);
Expand Down

0 comments on commit 1c80830

Please sign in to comment.