F
Filament12mo ago
danzzz

Show/Hide Table Columns based on getTabs()

I'm using the getTabs() method to filter records. I wan't to show/hide columns in my Table, based on which tab the user clicked. How can I do this?
Solution:
I do it similarly:
->visible(fn (HasTable $livewire): bool => $livewire->activeTab !== 'all')
->visible(fn (HasTable $livewire): bool => $livewire->activeTab !== 'all')
...
Jump to solution
3 Replies
jaocero
jaocero12mo ago
Hmmm this is how I use it:
Tables\Columns\TextColumn::make('created_at')
->label('Submitted On')
->date('F j, Y g:i A')
->searchable()
->sortable()
->wrap()
->hidden(function ($livewire) {
if ($livewire->activeTab === 'scheduled' || $livewire->activeTab === 'active' || $livewire->activeTab === 'ended') {
return true;
}
return false;
}),
Tables\Columns\TextColumn::make('created_at')
->label('Submitted On')
->date('F j, Y g:i A')
->searchable()
->sortable()
->wrap()
->hidden(function ($livewire) {
if ($livewire->activeTab === 'scheduled' || $livewire->activeTab === 'active' || $livewire->activeTab === 'ended') {
return true;
}
return false;
}),
maybe you can use in_array('status', array_here) if you have multiple status
Solution
DrByte
DrByte12mo ago
I do it similarly:
->visible(fn (HasTable $livewire): bool => $livewire->activeTab !== 'all')
->visible(fn (HasTable $livewire): bool => $livewire->activeTab !== 'all')
danzzz
danzzzOP12mo ago
thx all, it's working with injecting $livewire
Want results from more Discord servers?
Add your server