F
Filament2mo ago
Moktar

manually refresh table content

Hello Filament world Is it possible to have an action button on the filament table for refreshing the content manually I know there is ->poll('10sec') but it's not suitable for my need Thanks
7 Replies
toeknee
toeknee2mo ago
press refresh on the page?
toeknee
toeknee2mo ago
Or you add a listener which is a refresh listener? like: https://laracasts.com/discuss/channels/filament/refresh-filament-table-component
Laracasts
JibayMcs
JibayMcs2mo ago
HI ! This is how I do this logic in my projects:
#[On('refreshTable')] // Listening to an event here
public function refreshTable()
{
$this->loadTable();
// or
$this-resetTable();
}
#[On('refreshTable')] // Listening to an event here
public function refreshTable()
{
$this->loadTable();
// or
$this-resetTable();
}
JibayMcs
JibayMcs2mo ago
I use it in a custom page using HasTable implementation (https://filamentphp.com/docs/3.x/tables/adding-a-table-to-a-livewire-component) In combination with a Form and their input being updated:
public function updated($name, $value)
{
if (in_array($name, ['startDate', 'endDate', 'filterQueries', 'ignoredSenders', 'allowedFolders', 'microsoftGraphUserId'])) {

if ($name === 'startDate' || $name === 'endDate') {
$this->data[$name] = Carbon::parse($value);

} else {
$this->data[$name] = $value;
}
//Here the magic happens
$this->dispatch('refreshTable');
}
}
public function updated($name, $value)
{
if (in_array($name, ['startDate', 'endDate', 'filterQueries', 'ignoredSenders', 'allowedFolders', 'microsoftGraphUserId'])) {

if ($name === 'startDate' || $name === 'endDate') {
$this->data[$name] = Carbon::parse($value);

} else {
$this->data[$name] = $value;
}
//Here the magic happens
$this->dispatch('refreshTable');
}
}
JibayMcs
JibayMcs2mo ago
So you can easylly use it in a custom Action
Moktar
MoktarOP2mo ago
Thanks a lot. I wish I can do that without custom page
ChesterS
ChesterS2mo ago
You don't need a custom page. Filament pages are livewire components, you can add listeners to those classes like you would to any other livewire component The suggestions so far should cover you. Look into livewire's event documentation for more details
Want results from more Discord servers?
Add your server