How to implement a custom page number input box in laravel 5 paging to jump to a custom page
大家讲道理
大家讲道理 2017-05-16 16:48:07
0
1
1760

Such as the title: There are hundreds of pages of data taken out from the database. However, the paginator provided by laravel only displays the pages before and after the current page.
But when I want to jump to a page that is not on the paging bar, I can only gradually reach the desired page through page jumps.
Is there a way to display an input box on the paging bar, where the user can enter a custom page number and then jump to the page to browse the data.

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
淡淡烟草味

I tell you clearly that it is possible, and it is very simple. There are two methods, both of which are operated under the views/vendor/paginationdirectory:

  1. Modifydefault.blade.php, similar code is as follows:

<ul class="pagination  no-margin pull-right">
    {{-- 首页 --}}
    @if ($paginator->onFirstPage())
        <li class="disabled">
            <span>首页</span>
        </li>
    @else
        <li>
            <a href="{{ $paginator->url(1) . '&limit=' . $paginator->perPage() }}">首页</a>
        </li>
    @endif

    {{-- 上一页 --}}
    @if ($paginator->onFirstPage())
        <li class="disabled">
            <span>上一页</span>
        </li>
    @else
        <li>
            <a href="{{ $paginator->previousPageUrl() . '&limit=' . $paginator->perPage() }}">上一页</a>
        </li>
    @endif

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

        <!-- Array Of Links -->
        @if (is_array($element))
            @foreach ($element as $page => $url)
                @if ($page == $paginator->currentPage())
                    <li class="active"><span>{{ $page }}</span></li>
                @else
                    <li><a href="{{ $url . '&limit=' . $paginator->perPage() }}">{{ $page }}</a></li>
                @endif
            @endforeach
        @endif
    @endforeach

    {{-- 下一页 --}}
    @if ($paginator->hasMorePages())
        <li>
            <a href="{{ $paginator->nextPageUrl() . '&limit=' . $paginator->perPage() }}">下一页</a>
        </li>
    @else
        <li class="disabled">
            <span>下一页</span>
        </li>
    @endif

    {{-- 尾页 --}}
    @if ($paginator->hasMorePages())
        <li>
            <a href="{{ $paginator->url($paginator->lastPage()) . '&limit=' . $paginator->perPage() }}">尾页</a>
        </li>
    @else
        <li class="disabled">
            <span>尾页</span>
        </li>
    @endif
</ul>
<ul class="clearfix"></ul>

{{-- 增加输入框,跳转任意页码和显示任意条数 --}}
<ul class="pagination pagination-sm no-margin no-padding pull-right">
    <li>
        <span data-toggle="tooltip" data-placement="bottom" title="输入页码,按回车快速跳转">
            第 <input type="text" class="text-center no-padding" value="{{ $paginator->currentPage() }}" id="customPage" data-total-page="{{ $paginator->lastPage() }}" style="width: 50px;"> 页 / 共 {{ $paginator->lastPage() }} 页
        </span>
    </li>
    <li>
        <span data-toggle="tooltip" data-placement="bottom" title="输入每页条数,按回车快速跳转">
            每页 <input type="text" class="text-center no-padding" value="{{ $paginator->perPage() }}" id="customLimit" data-total="{{ $paginator->total() }}" style="width: 50px;"> 条 / 共 {{ $paginator->total() }} 条
        </span>
    </li>
</ul>
  1. Customize a paging template file, such as custom.blade.php,然后在其他模板中的分页方法参数中指定这个分页模板,如{!! $articles->render('vendor/pagination/custom') !!};

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template