Is there a way to intercept the activeTab parameter in the resource table function?
I want to change the table structure depending on the tab that was just clicked. I can get the value after you leave the tab using
$table->getLivewire()->activeTab
(as the tab is probably only available after the table has rendered).
I would like to do something like:
TIA8 Replies
Would you like to show/hide columns on a specific tab?
It may be enough wish you could do
$table->hidden()
. Let me see if the above is enough. Thanks.No. It isn't. We want to swap out the entire table because the columns to be displayed are different. Different table headers, different parent eloquent query.
Also, it is cleaner to not have to load all that data if the view isn't using it.
@Ola A @Leandro Ferreira Yeah the problem is this doesn't change the underlying query. Be better if we can pull in a different table.
Ok I have found a "hacky" way around this. I overrode the
vendor/filament/components/tabs/item.blade.php
so I could add a click event (there is already a wire:click on there but it just sets and not dispatched).
I then listen for the event in the list page like so:
This refreshed the table again so you can get the current tab value (without it you can only get the previous tab value as the page doesn't refresh between tab changes).
I now have access to the current active tab and can then switch tables based on this.
I had
<x-filament::tabs.item :active="$activeTab === 'termes'" wire:click="$set('activeTab', 'termes')" >Termes</x-filament::tabs.item>
But I don't know how to listen for $set, so $set was called AFTER table($table) and $this->activeTab had the old incorrect tab.
If somebody can tell me what function do I have to create to listen $set('somevar','somevalue') I would appreciate. So far I tried updateSomevar($somevalue), but it does not work.
Anyway, I ended up changing the calls:
<x-filament::tabs.item :active="$activeTab === 'frases'" wire:click="setTabTo('frases')">Frases</x-filament::tabs.item>
This way I can create a function in my component:
public function setTabTo($tab) {
$this->activeTab=$tab;
$this->resetTable();
return;
}
That changes the variable and then resets the table. The table function is called twice, as table is called before seting the variable, but it seems to work.did you try
updatedActiveTab()
in the ListPage?GREAT, that works.
So I only need to create
public function updatedActiveTab() {
// It tells me this parent function does not exists. parent::updatedActiveTab();
$this->resetTable();
}
And this way table gets called twice, but the second time $this->activeTab holds the correct value.
Thanks!!