Hide column in table conditionally

I checked the documentation and all they give is the attached image example... What I need to do is hide a column if another column has a value In this specific example: if born column is NULL, I need expected column to be shown if born column is SET, I need expected column to be hidden
No description
4 Replies
tuto1902
tuto1902•11mo ago
Hmm, that's a very good question 🤔 I'll do some digging and let you know what I can find. Quick question thou, you don't really need to hide the entire column, just the value of that column, right? Because you can have rows with where born is set, and other rows where born is null. You could use the ->state() method. This will give you the current row you are working on and can decide on the value of the current row's column.
Tables\Columns\TextColumn::make('expected')
->state(function (Model $record) {
if (! $record->born) {
return $record->expected
}
}),
Tables\Columns\TextColumn::make('expected')
->state(function (Model $record) {
if (! $record->born) {
return $record->expected
}
}),
JamesTechDude
JamesTechDude•11mo ago
Yeah it would be row specific, not the whole column - my fault Oh! Okay I'll try that out, I didn't even know that was possible
JamesTechDude
JamesTechDude•11mo ago
It works! Just forgot a ; at the end of $record->expected Thank you so much, you're the best