• 分页显示页数过多


    原文:http://blog.csdn.net/u011897510/article/details/77823390

    核心代码:

    @if ($paginator->hasPages())
        @php
        //指定显示的页码数量,取值范围3-n
        $paging_number = 6;
        if($paging_number<3){
        $paging_number = 3;
        }
        //当前页
        $paging_current_page = $paginator->currentPage();
        //共几页
        $paging_last_page = $paginator->lastPage();
        if(($paging_number%2) == 0){
        if($paging_last_page <= $paging_number){
        $paging_start = 1;
        $paging_end = $paging_last_page;
        }else if($paging_current_page < ($paging_number/2+1)){
        $paging_start = 1;
        $paging_end = $paging_number;
        }else if($paging_current_page >= ($paging_number/2+1) && (($paging_current_page + ($paging_number/2 - 1)) <= $paging_last_page)){
        $paging_start = $paging_current_page - ($paging_number/2);
        $paging_end = $paging_current_page + ($paging_number/2 - 1);
        }else{
        $paging_start = $paging_last_page - $paging_number + 1;
        $paging_end = $paging_last_page;
        }
        }else{
        if($paging_last_page <= $paging_number){
        $paging_start = 1;
        $paging_end = $paging_last_page;
        }else if($paging_current_page < ceil($paging_number/2)){
        $paging_start = 1;
        $paging_end = $paging_number;
        }else if($paging_current_page >= ceil($paging_number/2) && (($paging_current_page + floor($paging_number/2)) <= $paging_last_page)){
        $paging_start = $paging_current_page - floor($paging_number/2);
        $paging_end = $paging_current_page + floor($paging_number/2);
        }else{
        $paging_start = $paging_last_page - ($paging_number - 1);
        $paging_end = $paging_last_page;
        }
        }
        @endphp
        <ul class="pagination">
            {{-- Previous Page Link --}}
            @if ($paginator->onFirstPage())
                <li class="disabled"><span>«</span></li>
            @else
                <li><a href="{{ $paginator->previousPageUrl() }}" rel="prev">«</a></li>
            @endif
    
            {{-- Pagination Elements --}}
            @for ($i = $paging_start; $i <= $paging_end; $i++)
                @if ($i == $paginator->currentPage())
                    <li class="active" ><span >{{ $i }}</span></li>
                @else
                    <li><a href="{{ $paginator->url($i) }}">{{ $i }}</a></li>
                @endif
            @endfor
    
            {{-- Next Page Link --}}
            @if ($paginator->hasMorePages())
                <li><a href="{{ $paginator->nextPageUrl() }}" rel="next">»</a></li>
            @else
                <li class="disabled"><span>»</span></li>
            @endif
        </ul>
    @endif
  • 相关阅读:
    蓝桥杯_买不到的数目
    蓝桥杯_错误票据
    蓝桥杯_数组操作
    剑指OFFER_把二叉树打印成多行
    C语言学习笔记_结构体的内存对齐
    剑指OFFER_二叉搜索树的第k个节点
    局域网ftp工具,带你去探索局域网ftp工具
    这就是Java代码生成器的制作流程(转载)
    ftp工具 绿色,一款非常棒的绿色 ftp工具
    HDFS+ClickHouse+Spark:从0到1实现一款轻量级大数据分析系统(转载)
  • 原文地址:https://www.cnblogs.com/wanlibingfeng/p/7767803.html
Copyright © 2020-2023  润新知