F
Filament8mo ago
CGM

How do I refresh my table when I interact with a ToggleColumn?

Is there an easy way to make ToggleColumn::make() reactive, or to get it to refresh the entire table after being toggled? I have other columns that depend on the state of these toggles, but I can't get the updates to the browser without refreshing the page manually. I've tried things like $this->dispatch('$refresh') from different column callbacks, etc but without any luck. Adding <button wire:click="$refresh">Refresh component</button> to a button works, but I want the table to refresh when the toggle is toggled.
ToggleColumn::make('roles.role_full_access')
->afterStateUpdated(function ($state, $record) {
$this->dispatch('$refresh'); // Doesn't cause table refresh
})
ToggleColumn::make('roles.role_full_access')
->afterStateUpdated(function ($state, $record) {
$this->dispatch('$refresh'); // Doesn't cause table refresh
})
5 Replies
CGM
CGMOP8mo ago
So I got the table to refresh by adding:
protected $listeners = ['updateRolesTable' => '$refresh'];
protected $listeners = ['updateRolesTable' => '$refresh'];
And then I call:
$this->dispatch('updateRolesTable');
$this->dispatch('updateRolesTable');
Which works now, but is there a way to accomplish this without the additional round trip?
krekas
krekas8mo ago
don't know in this case but maybe just $this->refresh() could work?
CGM
CGMOP8mo ago
I thought I remembered that being a thing before too, but it says 'Method does not exist'. Was this once a livewire method? I don't see it in the current docs either.
krekas
krekas8mo ago
I don't remember. I think I saw it in the filament source
CGM
CGMOP8mo ago
So it ends up using a checkbox column is way more robust. Toggles get out of sync really fast if there is latency and you're updating other columns in the background.
Want results from more Discord servers?
Add your server