Hekmatyar's avatar

Livewire Pagination - action's not working

Why there is so much problems with this pagination from livewire? i have been see many topics of this.. and srsly i don't get it.. https://i.imgur.com/PENGFjf.gifv <- problem

if i go manualy and i write "?page=2" in url adress it is working, but i don't have any actions inside, clicking in pagination buttons

| "laravel/framework": "^8.54", | "laravel/jetstream": "^2.3", | "laravel/sanctum": "^2.6", | "laravel/tinker": "^2.5", | "livewire/livewire": "^2.5"

<?php

namespace App\Http\Livewire;

use App\Models\Product;
use Livewire\Component;
use Livewire\WithPagination;

class ShopComponent extends Component
{
     use WithPagination;
  
    
    public function render()
    {    
        return view('livewire.shop-component', ['products' => Product::paginate(9)])->layout('layouts.base');
    }

    public function paginationView()
    {
        return 'livewire.custom-pagination';
    }
}

Custom pagination is copy from vendor - bootstrap pagination


    <div>
        @if ($paginator->hasPages())
        <nav class="pagination justify-content-center">
            <ul class="pagination mt-30 mb-30">
                {{-- Previous Page Link --}}
                @if ($paginator->onFirstPage())
                    <li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.previous')">
                        <span class="page-link" aria-hidden="true">&lsaquo;</span>
                    </li>
                @else
                    <li class="page-item">
                        <button type="button" dusk="previousPage" class="page-link" wire:click="previousPage" wire:loading.attr="disabled" rel="prev" aria-label="@lang('pagination.previous')">&lsaquo;</button>
                    </li>
                @endif

                {{-- Pagination Elements --}}
                @foreach ($elements as $element)
                    {{-- "Three Dots" Separator --}}
                    @if (is_string($element))
                        <li class="page-item disabled" aria-disabled="true"><span class="page-link">{{ $element }}</span></li>
                    @endif

                    {{-- Array Of Links --}}
                    @if (is_array($element))
                        @foreach ($element as $page => $url)
                            @if ($page == $paginator->currentPage())
                                <li class="page-item active" wire:key="paginator-page-{{ $page }}" aria-current="page"><span class="page-link">{{ $page }}</span></li>
                            @else
                                <li class="page-item" wire:key="paginator-page-{{ $page }}"><button type="button" class="page-link" wire:click="gotoPage({{ $page }})">{{ $page }}</button></li>
                            @endif
                        @endforeach
                    @endif
                @endforeach

                {{-- Next Page Link --}}
                @if ($paginator->hasMorePages())
                    <li class="page-item">
                        <button type="button" dusk="nextPage" class="page-link" wire:click="nextPage" wire:loading.attr="disabled" rel="next" aria-label="@lang('pagination.next')">&rsaquo;</button>
                    </li>
                @else
                    <li class="page-item disabled" aria-disabled="true" aria-label="@lang('pagination.next')">
                        <span class="page-link" aria-hidden="true">&rsaquo;</span>
                    </li>
                @endif
            </ul>
        </nav>
    @endif
        
</div>

shop-component https://i.imgur.com/bob483q.png

0 likes
16 replies
Snapey's avatar

check you have livewire scripts loaded on the page

1 like
teos_97's avatar

Stupid guess but try adding .prevent modifier on the custom pagination view buttons. So where you have wire:click="someMethod" do wire:click.prevent="someMethod"

Hekmatyar's avatar

Nothing helps, i tested 4 views of pagination from vendor and any of those is not working

-bootstrap simply -bootstrap -tailwind -tailwind simply

Hekmatyar's avatar
  • composer update
  • php artisan cache:clear
  • php artisan route:clear
  • php artisan view:clear

still nothing, i have no ideas..

Snapey's avatar

have you checked the browser console for javascript errors?

teos_97's avatar

That’s really odd - any chance you can mae a public repo with livewire that has the issue so we can clone and debug?

teos_97's avatar
teos_97
Best Answer
Level 9

@hekmatyar Hey thanks for publishing it. Only thing I DID TO MAKE IT WORK was to give your shop-component.blade.php a SINGLE ROOT element. I put a

//shop-component.blade.php 
<div> ... (all your existing html) and closed it </div> at the end. 

test

Please or to participate in this conversation.