Skip to content

Commit

Permalink
Merge pull request #55 from awcodes/fix/fields-without-names
Browse files Browse the repository at this point in the history
Fix: allowing fields without names, like 'Actions'
  • Loading branch information
awcodes authored Aug 6, 2023
2 parents f4967fb + dbe49e8 commit 5dc4386
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
])
```

Expand Down
10 changes: 8 additions & 2 deletions resources/views/components/table-repeater.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 3 additions & 1 deletion src/Components/TableRepeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5dc4386

Please sign in to comment.