Is it possible to have a table action call a JS/Alpine method instead of a Livewire method?
I'd like to have an action be processed on the client-side, rather than with Livewire, which would be server-side. Is it possible to make an action call a JS/Alpine method? Emitting an event would also work.
Also, can actions such as sorting and filtering be done client-side?
For the actions, it seems like I use custom columns to do it, but I'd like to hear other ideas.
My use case:
I have a JS queue stored on local-storage. Whenever an action is called, it should be added to this queue (the action is just a request), and processed in order. This is to remediate unreliable internet, I want users to still be able to use the table and perform actions when the network goes offline, the queue attempts to process actions and retries them when the network is back online.
12 Replies
Found this interesting method:
extraAlpineAttributes
, but can't find any documentation about itYou can add alpine attributes that could dispatch a browser event then do something with it, but I don’t think there’s a a way to add an alpine function to the column.
Also, you can’t do sorting and filtering from the client side, since they have to interact with the database.
Got it, sorting/filtering isn't as important so that's ok. Is there documentation on dispatching browser events with an action? I couldn't find anything
What do you mean by ‘an action’? Just so we’re on the same page.
a table action, at the end of a table row
Filament
Emit Livewire event from Table Actions by Uzzair B - Tricks - Filament
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
This is what I'm trying to do, so to be able to catch the event from Alpine I just need to use
dispatchBrowserEvent
instead of emit
?Yea, but that’s not really going to solve your problem, I don’t think. Since it still a livewire event it’ll make a server request.
Let me check something real quick though.
Could probably make a custom action with a blade view that is an alpine component with your functionality.
I was thinking of making a custom column, is this what you mean?
No, you can just make an Action yourself. You shouldn’t need a column for that.
Filament
Actions - Table Builder - Filament
The elegant TALL stack table builder for Laravel artisans.
I think there’s a ->view() method you can use to pass it a blade view. Not 100% though.