Can I get a Filament (v2) Action to refresh the whole page, or at least update a Navigation Badge?
I’ve got a table of Recipes, and I’ve got a Single Action on that recipe table, which adds the recipe to a Menu.
And i’ve got a Resource for the Menu, which has a Navigation Badge which shows the number of Recipes in that Menu.
But when I click the Action to add a Recipe to the Menu, it doesn’t immediately update the Navigation Badge. I have to refresh the page in the browser to see the updated Navigation Badge.
Is there some way I can get the Action to be Reactive, so that it updates the whole page? Or even a way to get the Action to trigger a refresh on the Nav Badge?
2
Answers
You can add redirect to action
or you can use livewire (lifecycle hooks )
https://filamentphp.com/docs/2.x/admin/resources/editing-records#lifecycle-hooks
it will look like this
we need to listen for the event and refresh the page. (in editFileName.php )
First you need to define a Filament Action with a callback function that runs after the action is executed.
In the callback function:
To refresh the whole page, use location.reload(true);.
To update the Navigation Badge, manipulate the DOM to change its content.
for example:
Replace ‘badgeId’ and ‘updatedCount’ with your specific IDs and values