Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

juanborras's avatar

Filament table, subscribe to an event

Hello All,

Within a filament table I want to subscribe to a pressed event button in order to perform some action, any ideas where to start?

Thanks!

0 likes
2 replies
LaryAI's avatar
Level 58

To subscribe to an event in a Filament table, you can utilize Livewire's event system. Filament tables are built on top of Livewire, so you can leverage Livewire's capabilities to listen for events and perform actions accordingly.

Here's a step-by-step guide on how you can achieve this:

  1. Create a Livewire Component: Ensure you have a Livewire component set up for your Filament table.

  2. Define the Event in JavaScript: You can trigger a Livewire event from JavaScript when a button is pressed. This can be done using the dispatch method.

  3. Listen for the Event in Livewire: In your Livewire component, you can listen for the event and define the action you want to perform.

Here's an example:

Step 1: JavaScript to Trigger the Event

In your Blade view or a separate JavaScript file, add an event listener to your button:

<button onclick="Livewire.emit('buttonPressed')">Press Me</button>

Step 2: Livewire Component to Listen for the Event

In your Livewire component, you can listen for the buttonPressed event and define the action you want to perform:

use Livewire\Component;

class YourFilamentTableComponent extends Component
{
    protected $listeners = ['buttonPressed' => 'handleButtonPressed'];

    public function handleButtonPressed()
    {
        // Perform your action here
        // For example, you might want to refresh the table or update some data
        $this->refreshTable();
    }

    public function refreshTable()
    {
        // Logic to refresh or update the table
    }

    public function render()
    {
        return view('livewire.your-filament-table-component');
    }
}

Step 3: Blade View

Ensure your Blade view is set up to render the Livewire component:

@livewire('your-filament-table-component')

With this setup, when the button is pressed, the buttonPressed event is emitted, and the handleButtonPressed method in your Livewire component is called, allowing you to perform any necessary actions.

This approach allows you to effectively subscribe to button press events within a Filament table and handle them using Livewire's event system.

1 like

Please or to participate in this conversation.