F
Filament8mo ago
Tjiel

How can I refresh the page after a filter is changed

Hey all, I am currently looking for a way to refresh the whole page whenever a filter of a table is changed. The reason for this is that I have a widget with a mapping tool. And whenever the filter is changed I want it to change map. The problem is that the map of this mapping tool, can not be changed unless the page is reloaded. These are my current filters:
->filters([
Tables\Filters\TrashedFilter::make(),
Tables\Filters\SelectFilter::make('locations')
->relationship('location', 'name')
])
->filters([
Tables\Filters\TrashedFilter::make(),
Tables\Filters\SelectFilter::make('locations')
->relationship('location', 'name')
])
Preferably it only refreshes the page when the transmitters filter gets changed, but I won't mind if there is a solution where it happens if either one gets updated.
7 Replies
Bdev
Bdev8mo ago
Hi Tjiel, I had similar problem try to inject current livewire component to your filter closures then do $livewire->dispatch('eventName') Remember to register listener in your component and pass it $refresh like this:
protected $listeners = [
'eventName' => $refresh,
];
protected $listeners = [
'eventName' => $refresh,
];
Tjiel
TjielOP8mo ago
Thanks for the responses I've currently added an action to the filters:
->filtersApplyAction(function () {
// Refresh the page
})
->filtersApplyAction(function () {
// Refresh the page
})
This action is running whenever a filter gets changed (like how I wanted it). The problem with the dispatch and then refreshing the livewire component is that for some reason the maping tool can't have multiple instances on the same page. Even if you delete/remove the previous one. So basicly I need a way to reload the page and then set the map url in the getFooterwidgets using the parameters of the filter. Here is how the data is passed in the getFooterWidgets:
protected function getFooterWidgets(): array
{
return [
AssetResource\Widgets\MapWidget::make(['mapUrl' => 'real.url']),
];
}
protected function getFooterWidgets(): array
{
return [
AssetResource\Widgets\MapWidget::make(['mapUrl' => 'real.url']),
];
}
Bdev
Bdev8mo ago
You could reach for laravel redirect method maybe something like this:
return redirect()->to(AssetResource::getUrl('list`));

return redirect()->to(AssetResource::getUrl('list`));

Tjiel
TjielOP8mo ago
Update: I just found a solution using livewire dispatch:
->filtersApplyAction(function (Component $livewire) {
$livewire->dispatch('refresh');
})
->filtersApplyAction(function (Component $livewire) {
$livewire->dispatch('refresh');
})
and then have a listener in the mapplicWidget like this:
protected $listeners = ['refresh'];
protected $listeners = ['refresh'];
And lastly have a livewire.on in the blade file:
Livewire.on('refresh', refresh => {
window.location.reload(true);
})
Livewire.on('refresh', refresh => {
window.location.reload(true);
})
now i only need to find out how to get the filters inside the getFooterWidget
Bdev
Bdev8mo ago
Great glad that you have sorted it out thats roughly what i meant with using listeners:)
Tjiel
TjielOP8mo ago
Yeah ty for that at first I didn't think about that but then i was thinking adding custom js and circled back to the dispatch you brought up
Want results from more Discord servers?
Add your server