From dbe49e8404e54cd009aa752335530ee3daf57d13 Mon Sep 17 00:00:00 2001 From: Adam Weston Date: Sun, 6 Aug 2023 12:25:45 -0400 Subject: [PATCH] Fix: allowing fields without names, like 'Actions' --- README.md | 6 +++++- resources/views/components/table-repeater.blade.php | 10 ++++++++-- src/Components/TableRepeater.php | 4 +++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a3c4013..c444b98 100644 --- a/README.md +++ b/README.md @@ -89,16 +89,20 @@ TableRepeater::make('social') ### Column Widths To set the width of columns in the table use the `columnWidths()` method. -Widths should be set in px as a string. +Widths should be set in px as a string. For fields that don't have names, such as `Actions` and `Group`, you have to give it an explicit id to target. ```php TableRepeater::make('social') ->columnWidths([ 'platform' => '200px', + 'action_field' => '100px', ]) ->schema([ Select::make('platform'), // will be 200px wide TextInput::make('handle'), // will be default stretched width + Actions::make([ + ... + ])->id('action_field'), // will be 100px wide ]) ``` diff --git a/resources/views/components/table-repeater.blade.php b/resources/views/components/table-repeater.blade.php index 38b6c25..e503796 100644 --- a/resources/views/components/table-repeater.blade.php +++ b/resources/views/components/table-repeater.blade.php @@ -117,8 +117,14 @@ class="filament-table-repeater-row md:divide-x md:divide-gray-950/5 dark:md:divi 'filament-table-repeater-column p-2', 'has-hidden-label' => $cell->isLabelHidden(), ]) - @if ($columnWidths && isset($columnWidths[$cell->getName()])) - style="width: {{ $columnWidths[$cell->getName()] }}" + @php + $cellKey = method_exists($cell, 'getName') ? $cell->getName() : $cell->getId(); + @endphp + @if ( + $columnWidths && + isset($columnWidths[$cellKey]) + ) + style="width: {{ $columnWidths[$cellKey] }}" @endif > {{ $cell }} diff --git a/src/Components/TableRepeater.php b/src/Components/TableRepeater.php index 060bcd9..a8bae65 100644 --- a/src/Components/TableRepeater.php +++ b/src/Components/TableRepeater.php @@ -85,11 +85,13 @@ public function getHeaders(): array $customHeaders = $this->evaluate($this->headers); - foreach ($this->getChildComponents() as $key => $field) { + foreach ($this->getChildComponents() as $field) { if ($field instanceof Hidden || $field->isHidden()) { continue; } + $key = method_exists($field, 'getName') ? $field->getName() : $field->getId(); + $item = [ 'label' => $customHeaders[$key] ?? $field->getLabel(), 'width' => $this->getColumnWidths()[$key] ?? null,