Conditionally hide SelectColumn based on email domain
I'm working on a Laravel project using FilamentPHP and need some help conditionally hiding a column in a table.
The
department_id
column should only display when the user’s email address does end with @mycompany.com
. If it doesn't, I'd like this column to be hidden for that specific row.
Is there a way to conditionally hide a column based on a record's attribute like this in FilamentPHP?6 Replies
You can disable the select according to the condition
Hi @LeandroFerreira Thanks for the suggestion! However, I’m actually looking to completely hide the column rather than just disable it. Appreciate the help!
visible won't work because you can't determine the column visibility by rows..
Sadly, this is not possible: https://github.com/filamentphp/filament/discussions/12239
GitHub
Visible Closure Table Column - Parameter Not Filled · filamentphp f...
Package Table builder Package Version v3.x.x How can we help you? I want to create a condition where columns can appear or hide according to the data row they pass. Usually we just enter a callback...
@LeandroFerreira I see, thanks! Any ideas on a workaround to just leave the column empty for certain rows?
maybe
->extraAttributes(fn (YourModel $record) => ['class' => str_ends_with($record->email, '@mycompany.com') ? '' : 'hidden'])
use lifecycle hooks to verify the values...