Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filament v3 error with TextColumn #114

Open
austincarpenter opened this issue Sep 5, 2023 · 2 comments
Open

Filament v3 error with TextColumn #114

austincarpenter opened this issue Sep 5, 2023 · 2 comments

Comments

@austincarpenter
Copy link
Contributor

With v3, a TextColumn can render badges. This can be multiple badges in the one cell if the state of the column is an array or Collection.

In my case, I have Tag models, with a name and colour attribute.

The following works in the resource table but not when exporting:

Tables\Columns\TextColumn::make('tags')
    ->badge()
    ->formatStateUsing(fn (Tag $state) => $state->name)
    ->color(fn (Tag $state) => $state->color->getColor())

The reason is because the column's formatState() method (and therefore formatStateUsing() for me) gets called, supplying the Model, not the Collection. This is due to the @foreach loop inside text-column.blade.php of Filament:

https://github.com/filamentphp/filament/blob/f1c299b36fcabf9f7c602bbf10b08df8137dc3a6/packages/tables/resources/views/columns/text-column.blade.php#L18-L37

Not sure the best approach to take here, because not all columns have this array-wrapping behaviour, only TextColumns. In this package, the type of column is not a property of pxlrbt\FilamentExcel\Columns\Column and therefore a conditional check for the type of column (if originating from the table) is not possible.

@pxlrbt what approach would you like to take here (if at all)? Happy to attempt a PR. 😀

@pxlrbt
Copy link
Owner

pxlrbt commented Sep 5, 2023

Hm, not sure why this is still an issue. Should this be handled by this part:

foreach (Arr::wrap($state) as $state) {
$state = $column->formatStateUsing === null
? $state
: $this->evaluate($column->formatStateUsing->getClosure(), [
'column' => $column->tableColumn,
'livewire' => $this->getLivewire(),
'record' => $record,
'state' => $state,
]);
$formattedState[] = $state;
}

@kdrmlhcn
Copy link

is there any solution? @pxlrbt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants