jquery.dataTable分页
jsp页面,引入几个js
<link type="text/css" rel="stylesheet" href="/library/css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="/library/plugins/datatables/dataTables.bootstrap.css">
<script type="text/javascript" src="/library/plugins/datatables/jQuery-2.1.4.min.js"></script>
<script type="text/javascript" src="/library/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/library/plugins/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/library/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="/library/plugins/datatables/common.js"></script> var ctx = "${pageContext.request.contextPath}";
并且写一个用于分页的table
<div style="margin-top:30px;width:40%;float:left;"><h3>签到情况</h3><table style="width:100%;" id="singIn"></table></div>
再写一个操作js,如下:
$(function(){
//查询签到、签退情况
loadTable(1);
//签到
$("#signIn").click(function(){
$("#checkType").val("1");
$("#signForm").submit();
});
//签退
$("#signOut").click(function(){
$("#checkType").val("2");
$("#signForm").submit();
});
});
//分页
function loadTable(checkType){
var columns = [
{"data": "inTime",header:"签到时间"},
{"data": "checkType",header:"签到"}
];
var params = {checkType:checkType};
//判断上传按钮权限-----------------------------
var buttons;
//buttons = {add:{fun:"upload",text:"上传文件"}};
//-----------------------------------------
var columnDefs ={
/* checkbox:true,
button:{
del:{//删除按钮
fun:"deleteFunction",//删除方法名称
text:"删除"
},
edit:{//修改按钮
fun:"editFunction",
text:"修改"
},
add:{
fun:"upload",
text:"上传文件"
}
},*/
button:buttons,
main:[{
"targets": 0,
render: function (a, b, c, d) {
return format(c.inTime,'yyyy-MM-dd HH:mm:ss');
}
},{
"targets":1//,
// render: function (a, b, c, d){
// return '<a style="color:#fff;" class="btn btn-primary btn-sm" href="${pageContext.request.contextPath}/jsp/scorm/updateScorm.jsp?id='+c.id+'&name='+c.name+'&intro='+encodeURI(encodeURI(c.intro))+'&timeopen='+c.timeopen+'&timeclose='+c.timeclose+'&maxgrade='+c.maxgrade+'&grademethod='+c.grademethod+'">修改</a>'
// +' <a style="color:#fff;" class="btn btn-primary btn-sm" href="javascript:if(confirm(\'你确定删除吗?\'))window.location.href=\'${pageContext.request.contextPath}/scorm/deleteScorm?id='+c.id+'\'">删除</a>';
// }
}]
};
table = $("#singIn").table({
url:ctx+"/bankCheck/findSign",
params:params,
columns:columns,
columnDefs:columnDefs,
iDisplayLength:15
});
}
var format = function(time, format){
var t = new Date(time);
var tf = function(i){return (i < 10 ? '0' : '') + i};
return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){
switch(a){
case 'yyyy':
return tf(t.getFullYear());
break;
case 'MM':
return tf(t.getMonth() + 1);
break;
case 'mm':
return tf(t.getMinutes());
break;
case 'dd':
return tf(t.getDate());
break;
case 'HH':
return tf(t.getHours());
break;
case 'ss':
return tf(t.getSeconds());
break;
}
})
}
//if(valContent()){
// $.post(ctx+"/field/updateField",{fieldId:fieldId,fieldType:fieldType1,fieldName:fieldName1,orderNumber:orderNumber1,isDisable:isDisable1,remark:remark1},function(msg){
// if(msg.success){
// table.reload(); --------------------table.reload()可用
// $("#updateModal").modal('hide');
// }
// });
// }
后台controller如下:
/**
* 描述:查询签到、签退列表
* @param start
* @param length
* @param tempStr
* @return
*/
@RequestMapping("/findSign")
@ResponseBody
public GridReturn findSign(Integer start,Integer length,Integer checkType){
GridReturn gr = service.findSign(start, length,checkType);
return gr;
}
GridReturn如下:
package com.yunzainfo.common.pojo;
import java.util.List;
public class GridReturn {
private int draw;//请求次数
private long recordsTotal;//总记录数
private long recordsFiltered;//过滤后记录数
private List<?> data;
public GridReturn(int draw,long recordsTotal,long recordsFiltered,List<?> data){
this.data=data;
this.draw=draw;
this.recordsFiltered=recordsFiltered;
this.recordsTotal=recordsTotal;
}
public int getDraw() {
return draw;
}
public void setDraw(int draw) {
this.draw = draw;
}
public long getRecordsTotal() {
return recordsTotal;
}
public void setRecordsTotal(long recordsTotal) {
this.recordsTotal = recordsTotal;
}
public long getRecordsFiltered() {
return recordsFiltered;
}
public void setRecordsFiltered(long recordsFiltered) {
this.recordsFiltered = recordsFiltered;
}
public List<?> getData() {
return data;
}
public void setData(List<?> data) {
this.data = data;
}
}
service如下:
@Override
public GridReturn findSign(Integer start, Integer length,Integer checkType) {
//获取userId
String userId = userDirectoryService.getCurrentUser().getId();
//获取siteId
String siteId = "";
try {
siteId = siteService.getSite(toolManager.getCurrentPlacement().getContext()).getId();
} catch (IdUnusedException e) {
e.printStackTrace();
}
Criteria criteria = new Criteria();
if(start!=null && length!=null){
criteria.setStart(start);
criteria.setLimit(length);
}
if(StringUtils.isNotBlank(siteId)){
criteria.put("siteId", siteId);
}
criteria.put("checkType", checkType);
criteria.put("userId", userId);
List<BankCheck> list = mapper.findList(criteria);
int total = mapper.getTotalCount(criteria);
GridReturn gridReturn = new GridReturn(criteria.getDraw(), total, total, list);
return gridReturn;
}
mapper如下:
<!-- 查询今天签到状态 -->
<select id="findList" parameterType="org.sakaiproject.util.Criteria"
resultType="com.yunzainfo.bank.module.bankCheck.pojo.BankCheck">
SELECT
check_id checkId,
in_time inTime,
out_time outTime,
user_id userId,
check_type checkType,
site_id siteId
FROM
bank_check
<where>
<if test="condition.checkId!=null">and check_id=#{condition.checkId}</if>
<if test="condition.inTime!=null">and in_time=#{condition.inTime}</if>
<if test="condition.outTime!=null">and out_time=#{condition.outTime}</if>
<if test="condition.userId!='' and condition.userId!=null">and user_id=#{condition.userId}</if>
<if test="condition.checkType!=null">and check_type=#{condition.checkType}</if>
<if test="condition.siteId!='' and condition.siteId!=null">and site_id=#{condition.siteId}</if>
</where>
order by in_time DESC,out_time DESC
<if test="limit!=0">limit #{start},#{limit}</if>
</select> <select id="getTotalCount" parameterType="org.sakaiproject.util.Criteria"
resultType="java.lang.Integer">
SELECT count(1)
FROM
bank_check
<where>
<if test="condition.checkId!=null">and check_id=#{condition.checkId}</if>
<if test="condition.inTime!=null">and in_time=#{condition.inTime}</if>
<if test="condition.outTime!=null">and out_time=#{condition.outTime},</if>
<if test="condition.userId!=''and condition.userId!=null">and user_id=#{condition.userId}</if>
<if test="condition.checkType!=null">and check_type=#{condition.checkType}</if>
<if test="condition.siteId!='' and condition.siteId!=null">and site_id=#{condition.siteId}</if>
</where>
</select>
最后结果如下:

jquery.dataTable分页的更多相关文章
- jquery datatable 获取当前分页的数据
使用jquery datatable 遇到分页分别求和时,找了半天才找到获取当前分页数据的方法,以此总结 var table=$('#example').DataTable( { "pagi ...
- jquery datatable如何动态分页
展开全部 一.分页 分页的基本思想是根据datatable的页码及每页显示的行数,将数据从数据库分段提出,然后再填充到表格中,以达到分页的效果. 这里需要用到datatable插件的几个属性: &qu ...
- 使用jQuery开发datatable分页表格插件
当系统数据量很大时,前端的分页.异步获取方式就成了较好的解决方案.一直以来,我都希望使用自己开发的 jquery 插件做系统. 现在,学习了 jquery 插件开发之后,渐渐地也自己去尝试着开发一些简 ...
- 分享在MVC3.0中使用jQuery DataTable 插件
前不久在网络上看见一个很不错的jQuery的DataTable表格插件.后来发现在MVC中使用该插件的文章并不多.本文将介绍在MVC3.0如何使用该插件.在介绍该插件之前先简单介绍一下,推荐该插件的原 ...
- JQuery Datatable用法
原文出处:http://sgyyz.blog.51cto.com/5069360/1408251 目标: 使用jQuery Datatable构造数据列表,并且增加或者隐藏相应的列,已达到数据显示要求 ...
- jQuery Datatable 转载
jQuery Datatable 实用简单实例 时间 2014-05-08 10:44:18 51CTO推荐博文 原文 http://sgyyz.blog.51cto.com/5069360/14 ...
- 使用jquery.datatable.js注意事项
本文链接:https://blog.csdn.net/ylg01/article/details/76463908写在最前面的话,如果不是维护老项目或者在老项目上二次开发尽量不要用这个表格插件 为什么 ...
- jquery datatable使用简单示例
目标: 使用 jQuery Datatable 构造数据列表,并且增加或者隐藏相应的列,已达到数据显示要求.同时, jQuery Datatable 强大的功能支持:排序,分页,搜索等. Query ...
- jquery dataTable汉化(插件形式)
1.jquery dataTable.js 官网:http://datatables.net/ 中文:http://dt.thxopen.com/ 2.汉化提示信息(放到xx.js中,引入即可) 注: ...
随机推荐
- 在Linux下和Windows下遍历目录的方法及如何达成一致性操作
最近因为测试目的需要遍历一个目录下面的所有文件进行操作,主要是读每个文件的内容,只要知道文件名就OK了.在Java中直接用File类就可以搞定,因为Java中使用了组合模式,使得客户端对单个文件和文件 ...
- codevs4096 删数问题
题目描述 Description 键盘输入一个高精度的正整数N,去掉其中任意S个数字后剩下的数字按原左右次序将组成一个新的正整数.编程对给定的N 和S,寻找一种方案使得剩下的数字组成的新数最小. 输入 ...
- php补充
PHP 教程 echo 和 print 之间的差异:echo - 能够输出一个以上的字符串print - 只能输出一个字符串,并始终返回 1提示:echo 比 print 稍快,因为它不返回任何值. ...
- QT点击"X"按钮,调用closeEvent()函数来实现调用特定事件(附:粗略介绍QT的信号与槽的使用方法)
背景: QT在用户关闭窗口(直接点击"X"键)时,程序一般都需要做一些善后的事情,就我现在的程序来说,既关闭USB.如何实现? 正文: 首先,在对应窗体的".h" ...
- 微信封号浪潮再起 A货假代购还能在朋友圈泛滥多久?
你的微信朋友圈是不是很活跃?是不是被很多所谓的名品所包围?没错,这些很多都是A货或假代购的伎俩.如果xmyanke的微信朋友圈出现这些东东,我就会直接屏蔽他的朋友圈权限.具体方法是:打开他的微信详细资 ...
- 《深入浅出WPF》笔记一
1.项目模板 Visual Studio自动配置编译器参数,并准备好一套基本的源代码. 2.App.xaml/App.xaml.cs 声明程序的进程,并指定程序的主窗体. 3.Attribute和Pr ...
- php 调用系统命令
system 与 exec 两者区别与联系:都会返回最后一行,命令执行成功的return返回值, 区别:system直接将输出内容echo出来,而exec将每一行输出内容保存到数组$output里. ...
- Javascript高级程序设计——函数声明与函数表达式的区别
在Javascript中,函数是Functioin类型的实例,所以函数也具备属性和方法,因为函数是对象,所以函数名自然就是指向对象的指针啦. 函数可以通过声明语法和表达式来定义: 声明:functio ...
- CentOS 6.5 3.0.4安装agentd
更改主机名为test3 [root@localhost ~]# cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=test3 关闭selinux [ ...
- DAY5 php + mysql 写一个简单的sql注入平台
php mysql 在浏览器输入用户名,去数据库查询.查到则显示在浏览器,查不到则显示空. sql 里面三个字段 id username password create table t1 (id in ...