zoukankan      html  css  js  c++  java
  • laravel二维数组手动分页显示

    示例:数组 $user 如下

    $user:
    array (size=5)
      'sort' => 
        array (size=71)
          14 => float 0.028616622341171
          15 => float 0.031555520560068
          16 => float 0.030877620651548
          17 => float 0.035307960620288
          18 => float 0.030833821224056
          19 => float 0.033605497937075
          20 => float 0.024648793795052
          
      'totalHours' => 
        array (size=71)
          14 => float 513.25
          15 => float 565.96
          16 => float 553.8
          17 => float 633.26
          18 => float 553.01
          19 => float 602.72
          20 => float 442.08
         
      'days' => 
        array (size=71)
          14 => float 59
          15 => float 62
          16 => float 64
          17 => int 69
          18 => float 62
          19 => float 60
          20 => float 52.5
         
      'dayHours' => 
        array (size=71)
          14 => float 8.7
          15 => float 9.13
          16 => float 8.65
          17 => float 9.18
          18 => float 8.92
          19 => float 10.05
          20 => float 8.42
          
    分页调用
    use IlluminatePaginationLengthAwarePaginator;
    use IlluminatePaginationPaginator;
    
    public function show(Request $request){
    //手动分页
            $users = $kaoqin;
            $perPage = 10;
            if ($request->has('page')) {
                $current_page = $request->input('page');
                $current_page = $current_page <= 0 ? 1 :$current_page;
            } else {
                $current_page = 1;
            }
    
            $item = array_slice($users, ($current_page-1)*$perPage, $perPage); //注释1
            $total = count($users);
    
            $paginator =new LengthAwarePaginator($item, $total, $perPage, $current_page, [
                'path' => Paginator::resolveCurrentPath(),  //注释2
                'pageName' => 'page',
            ]);
    
            $userlist = $paginator->toArray()['data'];
    
            return view('web.attendance.groupList',compact('userlist', 'paginator'));
        }    
    
    
     
    html页面显示:
    <body >
        <table  width="100%" class="table table-hover">
            <tr class="info">
                <th style="align-content: center; 15%">姓名</th>
                <th style="align-content: center; 30%">时间</th>
                <th style="align-content: center; 15%">状态</th>
                <th style="align-content: center; 40%">原因</th>
            </tr>
            @if(!empty($userlist))
                @foreach($userlist as $person)
                    <tr >
                        <td style="vertical-align: middle;">{{$person['name']}}</td>
                        <td style="vertical-align: middle;">{{$person['time']}}</td>
                        <td style="vertical-align: middle;">{{$person['status']}}</td>
                        <td style="vertical-align: middle;">{!! $person['reason'] !!}</td>
                    </tr>
                @endforeach
            @endif
        </table>
        <div class="text-center">
            {{ $paginator->links() }}
        </div>
    </body>
    </html>


      上面的代码中的重点是$item,如果不做注释1处理,得出的是所有数据。

      注释2处就是设定个要分页的url地址。也可以手动通过 $paginator ->setPath(‘路径’) 设置。

      页面中的分页连接也是同样的调用方式 {{ $paginator->render() }}

  • 相关阅读:
    【hive】null值判断
    【hive】where使用注意的问题
    【hive】关于浮点数比较的问题
    【hive】在alter修改元数据的时候报错 mismatched input 'xxxxx' expecting KW_EXCHANGE
    破解诅咒心法
    泡妞心法
    awk高级
    排除故障的总结
    机房运维相关面试题
    统计流入流出流量
  • 原文地址:https://www.cnblogs.com/wanlibingfeng/p/7568578.html
Copyright © 2011-2022 走看看