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" ...
随机推荐
- 简单的dp(dp专题)
题目链接:https://vjudge.net/contest/216347#problem/C Alice gets two sequences A and B. A easy problem ...
- Washing Plates 贪心
https://www.hackerrank.com/contests/101hack41/challenges/washing-plates 给定n个物品,选这个物品,贡献 + p, 不选的话,贡献 ...
- 上机练习2 生成计算机ID
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- 自动布局库--Masonry使用
参考资料(戳这里): > Masonry官网 > Masonry介绍与使用实践(快速上手Autolayout) > iOS 开发实践之 Auto Layout > Ma ...
- maven(多个模块)项目 部署 开发环境 问题处理历程【异常Name jdbc is not bound in this Context 异常java.lang.NoSuchMethodE】
maven(多个模块)项目 部署 开发环境 问题处理历程[异常Name jdbc is not bound in this Context 异常java.lang.NoSuchMethodE] 201 ...
- 《敏捷软件开发:原则、模式与实践(C#版)》源代码下载
Agile Software Development: Principles, Patterns and Practice (C# Edition) Source Code 这本书的经典性无需多言 ...
- vue地址插件多级联动自适应 + github地址
https://github.com/cqzyl/vue-manyAddress
- H5如何做手机app(移动Web App)?图片轮播?ionic、MUI
移动Web App 跨平台开发 用户不需要去卖场来下载安装App 任何时候都可以发布App只需要一个开发项目 可以使用HTML5,CSS3以及JavaScript以及服务器端语言来完成(PHP,Rub ...
- 【Android开发笔记】程序崩溃异常总结
广播注册相关(broadcastReceiver) 没有注册广播就注销广播 注册广播但未注销广播 注册广播后重复注销广播 解决办法: 添加一个布尔变量,注册广播后为true,若为true在执行注销,注 ...
- 【Android开发笔记】返回上层Activity的正确打开方式
技术支持 http://stackoverflow.com/questions/12276027/how-can-i-return-to-a-parent-activity-correctly 首先, ...