Search code examples
laraveldatatableslaravel-bladelaravel-livewirealpine.js

Livewire : Wire click event handler not working on 2nd page or higher datatables


I am trying to trigger a livewire function from a wire:click in a datatables array.

This system works fine but only for the first datatable page. Nothing is triggered in the 2nd page or higher.

Here is my code :

event.php :

public function showEvent($eventId)
{
 return redirect()->route('events.show', [$eventId]);
}

event.blade.php :

<table class="table align-items-center mb-0 responsive" id="event-table" wire:ignore>
    <thead>
      <tr>
        <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">
          Nom
        </th>
      </tr>
     </thead>
    <tbody>
 @foreach ($events as $event)
  <tr class="px-3" wire:key="{{ $event->id }}">
      <td class="ps-2 ps-md-4" data-label="Nom" wire:click="showEvent({{ $event->id }})">
  </tr>
 @endforeach
  </tbody>
 </table>

Any suggestion ? Thanks


Solution

  • Why you use livewire for this sulotion.

    if rediorect to any page:

    use a tag to redirect,

    if show partial view in current page:

    return view in showEvent method.