Table 分页处理
介绍两种table分页处理:PHP分页 和 js(jquery.table)分页。
一:jquery.table:
1:下载两个文件:table_jui.css 和 jquery.dataTables.min.js(当然前面的加载 jquery.js文件);将其拉入html 前面。
table_jui.css 和 jquery.dataTables.min.js
2:建表:
<table style="width: 100%; margin-bottom:8px; " class="dataTables_wrapper table" id="tablemsg">
<thead style="font-size: 15px; font-weight: 800; background-color: #E7E5DA;">
<tr>
<td>用户ID</td>
<td>反馈问题</td>
<td>设备类型</td>
<td>应用版本</td>
<td>系统版本</td>
<td>反馈时间</td>
<td>最后回复</td>
</tr>
</thead>
<tbody id="tablelise" style="table-layout: fixed; word-wrap: break-word;">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
3:js插入数据:
function showGcmList() {
var datable = $('#tablemsg').dataTable({ "bDestroy": true});
datable.fnClearTable();
for (var i = 0; i < data.length; i++) {
$tr = $('<tr>' +
'<td>' + data[i].userid + '</td>' +
'<td>' + msg + '</td>' +
'<td >' + data[i].devicetype + '</td>' +
'<td >' + data[i].appver + '</td>' +
'<td >' + data[i].osver + '</td>' +
'<td >' + data[i].msgtime + '</td>' +
'<td>'+ data[i].id + '</td>' +
'</tr>')
$('#tablelise').append($tr);
}
$("#tablelise tr:odd").addClass("tabEven");
tableui();
}
注: var datable = $('#tablemsg').dataTable({ "bDestroy": true}); datable.fnClearTable(); 是对table中的数据清空(同$('#tablelise').empty();).
4:tableui() 函数就是对table表的渲染(每个属性,下面会有详细介绍):
function tableui() {
$(function () {
$("#tablemsg").dataTable({ //表的ID
"bDestroy": true,
"bPaginate": true, //开关,是否显示分页器
"bJQueryUI": false, //开关,是否启用JQueryUI风格
"bAutoWidth": false, //自适应宽度
"bFilter": true, //是否显示模糊查询
"bProcessing": false,
"bStateSave": true, //是否开启cookie,当需要对table的数据处理后,依然停留在该页数据。
"bSort": true, //是否排序
"bLengthChange": true, //开关,是否显示每页大小的下拉框
"aLengthMenu": [30, 50, 60],//下拉框的值
"iDisplayLength": 30, //下拉框的初始值
"aaSorting": [[5, "desc"]], //当bSort为true是起作用,即table的第6行按降序排。
"sPaginationType": "full_numbers", //table脚标显示
"aoColumns": [ //每列的宽度(可省略)
{ sWidth: '80px' },
{ sWidth: '23%' },
{ sWidth: '80px' },
{ sWidth: '80px' },
{ sWidth: '80px' },
{ sWidth: '100px' },
{ sWidth: '23%' },
],
"oLanguage": {
"sProcessing": "正在加载中......",
"sLengthMenu": "每页显示 _MENU_ 条记录",
"sZeroRecords": "对不起,查询不到相关数据!",
"sEmptyTable": "表中无数据存在!",
"sInfo": "当前显示 _START_ 到 _END_ 条,共 _TOTAL_ 条记录",
"sInfoFiltered": "数据表中共为 _MAX_ 条记录",
"sSearch": "模糊搜索",
"oPaginate": {
"sFirst": "首页",
"sPrevious": "上一页",
"sNext": "下一页",
"sLast": "末页"
}
}
});
});
}
5:效果:
"bFilter" : true 属性是否显示搜索: 
"bLengthChange": true 属性是否显示每页的显示值:
其中 aLengthMenu 的值为下拉框的各个值,iDisplayLength 为初始值。
"sPaginationType": "full_numbers" 属性设置分页脚的显示样式 
最终显示效果:

二:PHP分页(ThinkPHP):
1:准备分页类文件 Page.class.php (类位于 /ThinkPHP/Library/Org/Util/ 文件夹下,如果没有,可在网上下载)。
2:后台PHP代码 function showTable():
function showTable(){
$table = M ( 'msg', '', 'DB_CONFIG' );
if(isset($_GET['p'])){
$p=$_GET['p'];
}else{
$p=1;
}
import("Org.Util.Page");//加载分页类
$countaql='select count(1) as count from fb_msg_android where userfeedback <> 0';
$count = $table->query($countaql); //查询数据
$page=new \Page(intval($count[0]['count']),8); //第一个参数是 数据总数,第二个参数是 每页显示的数据个数
$sqlstrmsg="select * from fb_msg_android where userfeedback <> 0 limit $page->firstRow,$page->listRows";
$data = $table->query($sqlstrmsg); //查询数据,从第一条到第8条
$page->setConfig('header','条记录'); //分页脚标设置
$page->setConfig('prev',"上一页");
$page->setConfig('next','下一页');
$page->setConfig('first','首页');
$page->setConfig('last','末页');
$show=$page->show(); //显示分页(必写)
$this->assign('select',$data); //查询数据渲染模板
$this->assign('page',$show); //渲染分页table
$this->display(); //显示面板
}
3:添加模板(html表):
<table class="table" border="1" style="width:100%;border-collapse:collapse;border:2px solid #000;text-align:center;">
<tr>
<th>系统ID</th>
<th>用户ID</th>
<th>信息</th>
<th>信息发布时间</th>
<th>操作数</th>
</tr> <foreach name='select' item='b'> <-- 后台的 $this->assign('select',$data); 的查询数据-->
<tr>
<td>{$b.id}</td>
<td>{$b.uid}</td>
<td>{$b.msg}</td>
<td>{$b.msgtime}</td>
<td>{$b.userfeedback}</td>
</tr>
</foreach>
<tfoot> <-- 必须有 tfoot 用于显示分页脚标 -->
<tr style="background-color:#000;color:#ffffff;">
<td colspan='5' align='right'>
{$page}
</td>
</tr>
</tfoot>
</table>
4:效果:

参考链接:http://blog.163.com/john_pei/blog/static/2046000172014270125286/
http://www.thinkphp.cn/info/192.html
http://blog.csdn.net/xiaojun1288/article/details/6861501
Table 分页处理的更多相关文章
- JQuery实现table分页
1.直接贴代码: ; //每页显示的记录条数 ; //显示第curPage页 var len; //总行数 var page; //总页数 $(function(){ len =$(; //去掉表头 ...
- html 布局;css3+jq 下拉菜单;table分页动态添加行;html5本地存储;简单易用的html框架
简单好用的html框架,预览图见最后: 源码: 1.页面布局使用table: table 嵌套 +iframe 布局: 2.下拉菜单为jq+css3 动画; css input 无边框,select下 ...
- 项目总结17-使用layui table分页表格
项目总结17-使用layui table分页表格总结 前言 在项目中,需要用到分页的表格来展示数据,发现layui的分页表格,是一个很好的选择:本文介绍layui table分页表格的前后端简单使用 ...
- Layui Table 分页记忆选中
Layui Table 分页记忆选中 挺好的功能,之前为什么放弃了,哈哈哈! 在最早的版本中,layui 的 table 会记录每页的勾选状态,但很多用户反馈这是 bug,因为当他们获取选中数据时,其 ...
- Table分页显示调整
这是table分页显示的代码,下面是对应调整的代码 /*分页调整*/ .fenye .dataTables_info{ line-height: 28px; } .fenye .pagination{ ...
- Bootstrap table分页问题汇总
首先非常感谢作者针对bootstrap table分页问题进行详细的整理,并分享给了大家,希望通过这篇文章可以帮助大家解决Bootstrap table分页的各种问题,谢谢大家的阅读. 问题1 :服务 ...
- bootstrap table分页(前后端两种方式实现)
bootstrap table分页的两种方式: 前端分页:一次性从数据库查询所有的数据,在前端进行分页(数据量小的时候或者逻辑处理不复杂的话可以使用前端分页) 服务器分页:每次只查询当前页面加载所需要 ...
- layui table 分页 序号始终从”1“开始解决方法
在用Layui table 分页显示数据,用 type:"numbers" 进行显示序号有以下的问题 1.表格自带的分页,page:true 这种分页,在切换页面的时候序号可以正常 ...
- 利用js制作html table分页示例(js实现分页)
有时候table的列数太长,不利于使用者查询,所以利用JS做了一个table的分页,以下为相关代码 一.JS代码 <script type="text/javascript" ...
随机推荐
- oracle 中的null与''
1.先看看Null与''在oracle中的表现 C:\Users\zen>sqlplus hr/hr SQL Production :: Copyright (c) , , Oracle. Al ...
- 经典PHP笔试题
1.考虑如下脚本.标记处应该添加什么代码才能让脚本输出字符串php? $alpha = 'abcdefghijklmnopqrstuvwxyz'; $letters = array(15, 7, 15 ...
- HDU 2586——How far away ?——————【LCA模板题】
How far away ? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- Life here can be a dream come true!
Life here can be a dream come true!美梦迟早会成真的!
- /opt/metasploit/msf3
启动msf终端 cd /opt/metasploit/msf3 msfconsole
- Hyper-V 2016 配置管理系列(准备篇)
2.1 推荐软硬件配置 2.2 Hyper主机前提准备 前提条件: 具有二级地址转换(SLAT)的64位处理器.要安装Hyper-V虚拟化组件(如Windows管理程序),处理器必须具有SLAT 足够 ...
- SQL 语句 使用附加和分离
use mastergo declare @flg int --返回0表示成功 否则表示失败declare @msg varchar(50) --显示成功或失败的消息declare @dbname v ...
- POJ 1631 Bridging signals(LIS的等价表述)
把左边固定,看右边,要求线不相交,编号满足单调性,其实是LIS的等价表述. (如果编号是乱的也可以把它有序化就像Uva 10635 Prince and Princess那样 O(nlogn) #in ...
- 【BZOJ1972】[SDOI2010] 猪国杀(恶心的大模拟)
点此看题面 大致题意: 让你模拟一个游戏猪国杀的过程. 几大坑点 对于这种模拟题,具体思路就不讲了,就说说有哪些坑点. 题面有锅,反猪是\(FP\). 数据有锅,牌堆中的牌可能不够用,牌堆为空之后需一 ...
- IPC Gateway 设计
1. IPC Gateway对外提供的功能: IPC的register/request/reply/notification服务. 2. IPC Gatew的实现原理: 各个具体的服务注册自己的回调函 ...