博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php+layui数据表格实现数据分页渲染
阅读量:4514 次
发布时间:2019-06-08

本文共 1704 字,大约阅读时间需要 5 分钟。

一、HTML

1 

二、JS

  说明:需要引入layui中的table和laytpl模板引擎,laytpl可以自定义事件及自定义数据字段等

1 
2 5 6
7 10 11

 

1 

 三、PHP

1 #这里是PHP类中主要的配合步骤 2  3 # 接收layui发送的limit 4 if (trim($_GET['limit'])) { 5     $limit = trim($_GET['limit']); 6 }else{ 7     $limit = 15; 8 } 9 10 # 按某字段排序,$rows为数据数组11 $sort_num = array_column($rows,'num');12 array_multisort($sort_num,SORT_DESC,$rows, SORT_DESC);13 14 # 调用自定义分页函数15 $datas = array();16 $datas = showpage($rows,$limit);17 18 $items = array();19 20 # 返回layui数据格式21 $items['data'] = $datas['rows'];22 $items['code'] = 0;23 $items['msg'] = 'ok';24 $items['count'] = $datas['tot'];25 26 exit(json_encode($items));
1 # showpage函数 2  3 function showpage($rows,$count){   4     $tot = count($rows); // 总数据条数 5  6     if ($_GET['page']) { //获取当前页码 7         $page = $_GET['page']; 8     }else{ 9         $page = 1;10     }11 12     // $count = $count; # 每页显示条数13 14     $countpage = ceil($tot/$count); # 计算总共页数15 16     $start = ($page-1)*$count; # 计算每页开始位置17 18     $datas = array_slice($rows, $start, $count); # 计算当前页数据19 20     # 获取上一页和下一页21     if ($page > 1) {22         $uppage = $page-1;23     }else{24         $uppage = 1;25     }26 27     if ($page < $countpage) {28         $nextpage = $page+1;29     }else{30         $nextpage = $countpage;31     }32 33     $pages['countpage'] = $countpage;34     $pages['page'] = $page;35     $pages['uppage'] = $uppage;36     $pages['nextpage'] = $nextpage;37     $pages['tot'] = $tot;38 39     //循环加入序号 , 避免使用$i引起的序号跳位40     $n = 1;41     foreach ($datas as &$data) {42         $data['n'] = $n;43         $n++;44     }45     46     $pages['rows'] = $datas;47 48     return $pages;49 }

 

转载于:https://www.cnblogs.com/yachyu/p/10768252.html

你可能感兴趣的文章
SQL*Plus 系统变量之32 - NEWP[AGE]
查看>>
Spring配置文件总结
查看>>
4.三角形面积
查看>>
基础-事务
查看>>
MAC下安装与配置MySQL [转]
查看>>
ERROR: ld.so: object '/usr/lib64/libtcmalloc.so.4' from LD_PRELOAD cannot be preloaded: ignored
查看>>
爬虫入门【10】Pyspider框架简介及安装说明
查看>>
android面试(4)---文件存储
查看>>
(转载) 标准C中的字符串操作函数
查看>>
如何提高android串口kernel log等级
查看>>
C#中值类型和引用类型的区别
查看>>
python学习笔记15-执行环境
查看>>
thinkphp 框架两种模式 两种模式:开发调试模式、线上生产模式
查看>>
iOS8中提示框的使用UIAlertController(UIAlertView和UIActionSheet二合一)
查看>>
Docker快速配置指南
查看>>
Python基础---OS模块 (二)
查看>>
【JS点滴】substring和substr以及slice和splice的用法和区别。
查看>>
awk多模式匹配
查看>>
线段树
查看>>
[javascript]实现登陆界面拖动窗口
查看>>