How can I refresh the options on a table filter after an action?
I have a select filter on a table called "collection" that filters records if they belong to that collection.
I also have a bulk create action to create a new collection and assign the selected records to the collection.
My problem is that if I create a new collection, I can't immediately filter the table with that new collection unless I hard refresh the page because the filter options haven't been updated. What do I need to do to have the filter update itself?
13 Replies
As far as I can get is adding a livewire listener on the list page and putting a
->dispatch()
on my action but the dispatch sends the event when the button is clicked, not when the form is submitted.
bumpAfter the bulk try? $this->refresh()
Where do I do that?
This is my code:
Also here is a gif of what I'm talking about:
I tried doing a
$livewire->dispatch('$refresh')
in my after()
method which does refresh the livewire component page but the options in the filter are not refreshed for some reason. I'm thinking maybe because they're filled in the mount()
method that only occurs during a hard refresh. Is there a way around this?Solution
OMG I solved it.
I changed my form from this:
to this:
I still don't understand why wrapping it in a closure fixes it. Does anyone else?
Because you’re allowing the closure to be run again, whereas as before it was a static array. As per the docs you should ensure your options are closures, or a full static array if it never changes. Any db selects in options have to be closures otherwise you end up with massive amounts of duplicate queries too.
Thanks for the reply. Do you mind linking the docs to me for this specific thing? I can't seem to find it, sorry 😄
This still isn't consistent. I'm so confused.
This does not refresh from the database when clicked:
But, a custom filter with this does:
try
BadMethodCallException PHP 8.2.16 10.48.4 Method Filament\Tables\Filters\SelectFilter::live does not exist.
Thank A LOTT.. Its workkk.. I have the same issue for a few hours...