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中,引入即可) 注: ...
随机推荐
- c++异常总结
堆栈辗转开解(stack-unwinding):如果一个函数中出现异常,在当前函数内即通过 try..catch 捕捉(且捕捉到)的话,可以继续往下执行:如果不捕捉(或未捕捉到)就会抛出(与通过 th ...
- MainData仿Backbone Model式 数据模型记录器
MainData仿Backbone Model式 数据模型记录器主要思想:将 数据记录处理 和 因为数据变化而产生的页面渲染 两者解耦, 让页面元素可以与数据进行关联绑定,杜绝因为遗忘或是逻辑复杂导致 ...
- Todd's Matlab讲义第5讲:二分法和找根
二分法和if ... else ... end 语句 先回顾一下二分法.要求方程\(f(x)=0\)的根.假设\(c = f(a) < 0\)和\(d = f(b) > 0\),如果\(f ...
- 64.SHELL
SHELL 1. crontab定时器 编辑使用crontab -e 一共6列,分别是:分 时 日 月 周 命令 查看使用crontab -l 删除任务crontab -r 查看crontab执行日志 ...
- C++实现对lua访问的封装
这是一个几年前写的对lua的访问封装,当时的项目仅提供了最基本的lua访问接口:调用lua函数,向lua注册标准格式的C++函数. 本来我想引进luabind,但luabind相对又过于复杂,并不是所 ...
- mysql explain用法和结果的含义
重点是第二种用法,需要深入的了解. 先看一个例子: mysql> explain select * from t_order; +----+-------------+---------+--- ...
- jQuery Ajax无刷新操作一般处理程序 ashx
//前台实例代码 aspx文件 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="ser ...
- 用jQuery编的一个分页小代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- HDU 1174 爆头(计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1174 解题报告:就是用到了三维向量的点积来求点到直线的距离,向量(x1,y1,z1)与(x2,y2,z ...
- Method Swizzling和AOP(面向切面编程)实践
Method Swizzling和AOP(面向切面编程)实践 参考: http://www.cocoachina.com/ios/20150120/10959.html 上一篇介绍了 Objectiv ...