F
Filament4mo ago
Hugo

Closure on column action doesn't work

Hi, there, I'm trying to put an action on a column through a closure. I don't want the action to open if there is no $record->url, however, as soon as I pass a closure the action doesn't fire at all and the modal never opens. I've noticed that as soon as I pass a closure in the action, the click event is no longer “mountTableAction” but “callTableColumnAction”. If anyone has any ideas 😄
Tables\Columns\IconColumn::make('url')
->icon('heroicon-o-document')
->placeholder('No media')
->action(function ($record) {
if ($record->url) {
return Tables\Actions\Action::make()
->modal()
->modalContent(new HtmlString('<iframe src="' . $record->url . '" class="w-full h-full"></iframe>'))
->modalHeading($record->url);
} else {
return null;
}
})
Tables\Columns\IconColumn::make('url')
->icon('heroicon-o-document')
->placeholder('No media')
->action(function ($record) {
if ($record->url) {
return Tables\Actions\Action::make()
->modal()
->modalContent(new HtmlString('<iframe src="' . $record->url . '" class="w-full h-full"></iframe>'))
->modalHeading($record->url);
} else {
return null;
}
})
Solution:
I think the problem here is that the action isn't getting registered. Try this: ```php ->action( Tables\Actions\Action::make('show_page_in_modal') ->disabled(fn ($record): bool => ! $record->url)...
Jump to solution
4 Replies
Hugo
HugoOP4mo ago
Up
Solution
awcodes
awcodes4mo ago
I think the problem here is that the action isn't getting registered. Try this:
->action(
Tables\Actions\Action::make('show_page_in_modal')
->disabled(fn ($record): bool => ! $record->url)
->modalContent(fn ($record) => new HtmlString('<iframe src="' . $record->url . '" class="w-full h-full"></iframe>'))
->modalHeading(fn ($record) => $record->url)
->action(fn () => null)
),
->action(
Tables\Actions\Action::make('show_page_in_modal')
->disabled(fn ($record): bool => ! $record->url)
->modalContent(fn ($record) => new HtmlString('<iframe src="' . $record->url . '" class="w-full h-full"></iframe>'))
->modalHeading(fn ($record) => $record->url)
->action(fn () => null)
),
Hugo
HugoOP4mo ago
Okay, that's how it worked, I hadn't thought of that. Thanks for your help !
Want results from more Discord servers?
Add your server