1. 程式人生 > >Laravel 自定義分頁樣式

Laravel 自定義分頁樣式

建立 img each IV com mina nta ner names

操作步驟如下:

(1) 對應public/css/paging.css 文件建立分頁樣式.

(2) 控制器查出分頁數據使用 paginate函數進行分頁處理.(禁止使用group by處理查詢).

(3) 對應視圖引入分頁樣式.

例如: paging.css 文件代碼(復制即可用,實際操作過)如下

    #pull_right{
        text-align:center;
    }
    .pull-right {
        /*float: left!important;*/
    }
    .pagination {
        display: inline-block;
        padding-left: 0;
        margin: 20px 0;
        border-radius: 4px;
    }
    .pagination > li {
        display: inline;
    }
    .pagination > li > a,
    .pagination > li > span {
        position: relative;
        float: left;
        padding: 6px 12px;
        margin-left: -1px;
        line-height: 1.42857143;
        color: #428bca;
        text-decoration: none;
        background-color: #fff;
        border: 1px solid #ddd;
    }
    .pagination > li:first-child > a,
    .pagination > li:first-child > span {
        margin-left: 0;
        border-top-left-radius: 4px;
        border-bottom-left-radius: 4px;
    }
    .pagination > li:last-child > a,
    .pagination > li:last-child > span {
        border-top-right-radius: 4px;
        border-bottom-right-radius: 4px;
    }
    .pagination > li > a:hover,
    .pagination > li > span:hover,
    .pagination > li > a:focus,
    .pagination > li > span:focus {
        color: #2a6496;
        background-color: #eee;
        border-color: #ddd;
    }
    .pagination > .active > a,
    .pagination > .active > span,
    .pagination > .active > a:hover,
    .pagination > .active > span:hover,
    .pagination > .active > a:focus,
    .pagination > .active > span:focus {
        z-index: 2;
        color: #fff;
        cursor: default;
        background-color: #428bca;
        border-color: #428bca;
    }
    .pagination > .disabled > span,
    .pagination > .disabled > span:hover,
    .pagination > .disabled > span:focus,
    .pagination > .disabled > a,
    .pagination > .disabled > a:hover,
    .pagination > .disabled > a:focus {
        color: #777;
        cursor: not-allowed;
        background-color: #fff;
        border-color: #ddd;
    }
    .clear{
        clear: both;
    }

例如:TestCntroller.php 控制器示例寫法

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;

class TestController extends Controller{
    /**
     * 測試數據
     */
    public function index()
    {
        $test = DB::table(‘test‘)->paginate(5);
        
return view(‘index‘, [‘test‘ => $test]); } }

例如: list.blade.php 視圖文件代碼示例寫法

<!--用於引用css-->
<link  rel="stylesheet" type="text/css" href="{{asset(‘css/paging.css‘)}}"/>

<div class="container">
    <!--查數據-->
    @foreach ($test as $value)
        {{ $value->id }}
    @endforeach
</div> <div id="pull_right"> <!--分頁寫法--> <div class="pull-right"> {{ $test->render() }} </div> </div>

樣式如下圖:

技術分享圖片

Laravel 自定義分頁樣式