Hide table column based on value of another column

How can I do this? In ->hidden(), I tried a closure passing the $record and accessing the attribute, and I tried passing Get and using $get('name'), but the first way passed null to the closure and the second told me "Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization"
Solution:
hide a table column based on a form might be possible.. but you cant hide a column per record because a table holds multiple records.. thats impossible for any table
Jump to solution
7 Replies
Jordy
Jordy3w ago
https://filamentphp.com/docs/3.x/forms/getting-started#dependant-fields ah not form, 1 sec or is it? your error says form, but the title says column/table?
fpolli
fpolliOP3w ago
that is a clue. Yes, I am trying to hide a table column:
Tables\Columns\TextColumn::make('actual_net')
->hidden(fn (Get $get) => $get('name') == 'Imported Budget')
->label('Actual Net')
->state(function (Budget $record): string {
return $record->actualNet()->formatTo('en_US');
}),
Tables\Columns\TextColumn::make('actual_net')
->hidden(fn (Get $get) => $get('name') == 'Imported Budget')
->label('Actual Net')
->state(function (Budget $record): string {
return $record->actualNet()->formatTo('en_US');
}),
LeandroFerreira
I think you can't show/hide a column by rows
Solution
Jordy
Jordy3w ago
hide a table column based on a form might be possible.. but you cant hide a column per record because a table holds multiple records.. thats impossible for any table
fpolli
fpolliOP3w ago
right that makes sense so I would use state to send a blank string on the rows Thanks!
fpolli
fpolliOP3w ago
yeah, I was already using state so I just added a conditional and it works like a charm

Did you find this page helpful?