layui分頁table表格使用


html:

<table id="demo" lay-filter="test"></table>

script:

 1 <script>
 2     layui.use('table', function () {
 3         var table = layui.table;
 4         
 5         table.render({
 6             elem: '#demo'
 7             , height: 380
 8             , url: '../php/main.php?type=rizhitb' //數據接口,請求的php頁面路徑
 9             , page: true //開啟分頁
10             , cols: [[ //表頭
11                 { field: 'account', title: '賬號', width: 150, sort: true, fixed: 'left' }
12                 , { field: 'name', title: '用戶名', width: 180 }
13                 , { field: 'date', title: '操作時間', width: 250, sort: true }
14                 , { field: 'content', title: '操作內容' }
15             ]]
16         });
17 
18     });
19 </script>

php:

 1 case 'rizhitb':
 2         $sql = "select count(*) from log";
 3         $res = $db->query($sql);
 4         $con = $res->fetch_row();
 5         
 6         $page = $_GET["page"];
 7         $limit = $_GET["limit"];
 8         $lit = ($page-1)*$limit.",".$limit;//數據分頁
 9 
10         $sql = "select * from log order by date desc limit ".$lit;
11         $res = $db->query($sql);
12     
13         $rows = array();
14         while($row=$res->fetch_assoc()){
15             $rows[] = $row;
16         }
17         $arr = array(
18             "code"=> 0,
19             "msg"=> "",
20             "count"=> $con[0],
21             "data"=>$rows
22         );
23         echo json_encode($arr);
24 
25         break;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM