<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String basepath = request.getContextPath();
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css"
href="<%=basepath%>/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
href="<%=basepath%>/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
href="<%=basepath%>/easyui/demo.css">
<script type="text/javascript" src="<%=basepath%>/easyui/jquery.min.js"></script>
<script type="text/javascript"
src="<%=basepath%>/easyui/jquery.easyui.min.js"></script>
</head>
<body>

<br>
<h2>Client Side Pagination in DataGrid</h2>
<p>This sample shows how to implement client side pagination in
DataGrid.</p>
<div style="margin: 20px 0;"></div>

<table id="dg" title="Client Side Pagination"
style="width: 700px; height: 300px"
data-options="
rownumbers:true,
singleSelect:true,
autoRowHeight:false,
pagination:true,
pageSize:10">
<thead>
<tr>
<th field="id" width="30%">id</th>
<th field="userName" width="30%">userName</th>
<th field="age" width="30%">age</th>
</tr>
</thead>
</table>
<script>
(function($) {
function pagerFilter(data) {
if ($.isArray(data)) { // is array
data = {
total : data.length,
rows : data
}
}
var dg = $(this);
var state = dg.data('datagrid');
var opts = dg.datagrid('options');
if (!state.allRows) {
state.allRows = (data.rows);
}
var start = (opts.pageNumber - 1) * parseInt(opts.pageSize);
var end = start + parseInt(opts.pageSize);
data.rows = $.extend(true, [], state.allRows.slice(start, end));
return data;
}

var loadDataMethod = $.fn.datagrid.methods.loadData;
$.extend($.fn.datagrid.methods,
{
clientPaging : function(jq) {
return jq.each(function() {
var dg = $(this);
var state = dg.data('datagrid');
var opts = state.options;
opts.loadFilter = pagerFilter;
var onBeforeLoad = opts.onBeforeLoad;
opts.onBeforeLoad = function(param) {
state.allRows = null;
return onBeforeLoad.call(this, param);
}
dg.datagrid('getPager').pagination({
onSelectPage : function(pageNum, pageSize) {
opts.pageNumber = pageNum;
opts.pageSize = pageSize;
$(this).pagination('refresh', {
pageNumber : pageNum,
pageSize : pageSize
});
dg.datagrid('loadData', state.allRows);
}
});
$(this).datagrid('loadData', state.data);
if (opts.url) {
$(this).datagrid('reload');
}
});
},
loadData : function(jq, data) {
jq.each(function() {
$(this).data('datagrid').allRows = null;
});
return loadDataMethod.call($.fn.datagrid.methods,
jq, data);
},
getAllRows : function(jq) {
return jq.data('datagrid').allRows;
}
})
})(jQuery);

function getData() {
var rows = "";
/* for (var i = 1; i <= 800; i++) {
var amount = Math.floor(Math.random() * 1000);
var price = Math.floor(Math.random() * 1000);
rows.push({
inv : 'Inv No ' + i,
date : $.fn.datebox.defaults.formatter(new Date()),
name : 'Name ' + i,
amount : amount,
price : price,
cost : amount * price,
note : 'Note ' + i
});
} */

$.ajax({
method : 'POST',
url : '/egoTest/user/getAjaxUser2.do',
async : false,
dataType : 'json',
success : function(data) {
rows = data;
},
error : function() {
alert('error');
}
});
return rows;
}

$(function() {
$('#dg').datagrid({
data : getData()
}).datagrid('clientPaging');
});
</script>
<br><br><br><br><br>
a index jsp page ! ${list}
<br>
<table border="1" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th width="100"><input type="checkBox" name="checkBox" /></th>
<th field="userId" width="100">用户ID</th>
<th field="userName" width="100">名称</th>
<th field="bigDepartId" width="100">年龄</th>
<th field="operation" width="100">操作</th>
</tr>
</thead>
<c:forEach items="${uList }" var="u">
<tr class="${status.index%2==1?'even':'odd' }">
<td><input type="checkBox" name="checkBox" /></td>
<td>${u.id}</td>
<td>${u.userName }</td>
<td>${u.age }</td>
<td><a href="/springMVC11/user/getUser.do?id=${u.id }">修改</a></td>
</tr>
</c:forEach>
</table>

</body>
</html>

@RequestMapping("/getAjaxUser2")
public void getAjaxUser2(HttpServletRequest request,
HttpServletResponse response, ModelMap modelMap) {
try {
response.setContentType( "text/html;charset=UTF-8");
List<User> uList = userService.getAllUser();
Map<String, Object> map = new HashMap<String, Object>();
// map.put( "total",total);
map.put("allRows", 57);
map.put("rows", uList);

JSONObject json = JSONObject.fromObject(map);
// String str = "aabbcc";
PrintWriter pw = response.getWriter();
pw.write(json.toString());
pw.flush();
pw.close();
} catch (Exception e) {
e.printStackTrace();
}
}

easyui datagrid加载数据和分页的更多相关文章

  1. 解决easyui datagrid加载数据时,checkbox列没有根据checkbox的值来确定是否选中

    背景:   昨天帮朋友做一个easyui datagrid的小实例时,才发现easyui datagrid的checkbox列,没有根据值为true或false来选中checkbox,当时感觉太让人失 ...

  2. Easyui datagrid加载数据时默认全选的问题

    问题描述: 最近使用 Easyui datagrid 展示数据,之前一直使用很正常,今天出现了一个怪异问题 加载数据后,只要点击选中列 ck 的任意行或多行,再刷新时整个datagrid的所有数据都 ...

  3. easyui datagrid加载数据的三种方式

    1.加载本地数据 var obj = {"total":2,"rows":[{id:"1",name:"一"},{id: ...

  4. easyui datagrid加载数据的两种方式

    1.加载本地数据 var obj = {"total":2,"rows":[{id:"1",name:"一"},{id: ...

  5. jquery easyui使用(三)······datagrid加载数据(已解决)

    <div id="table_Data"> </div> $("#table_Data").datagrid({ toolbar: '# ...

  6. easyui datagrid 加载静态文件中的json数据

    本文主要介绍easyui datagrid 怎么加载静态文件里的json数据,开发环境vs2012, 一.json文件所处的位置 二.json文件内容 {"total":28,&q ...

  7. easyui datagrid加载成功之后选定并获取首行数据

    //加载成功之后,选定并获取首行数据 onLoadSuccess:function(data){ alert("grid加载成功"); var rows=$('test').dat ...

  8. easyui datagrid 加载两次请求,触发两次ajax 请求 问题

    datagrid初始化的时候请求两次URL 两种情况 1. <table id="gridview" class="easyui-datagrid"> ...

  9. easyui datagrid 加载 历险记(dom中已经加载,fit:true 时改变浏览器大小是会显示出来)

    (dom中已经加载,fit:true 时改变浏览器大小是会显示出来) 第一个想到的就是resize datagird  大小!可是没有用 ... 答案是加载的的div height为0导至的(//To ...

随机推荐

  1. python中交换两个值的方法

    a = 4b = 5 #第1种c = 0c = aa = bb = c #第2种a = a+bb = a-ba = a-b #第3种a,b = b,a 第三种办法本质上是元组之间的赋值 print(& ...

  2. Docker应用之仓库

    仓库是存放镜像的地方 注册服务器是管理仓库的具体服务器,每个服务器上可以有多个仓库,每个仓库也可以有多个镜像 如 dl.dockerpool.com/ubuntu ,dl.dockerpool.com ...

  3. MyEclipse weblogic Deploy Location项目名称不正确解决方案

    MyEclipse weblogic Deploy Location项目名称不正确 MyEclipse部署weblogic 项目,名称错误,是别的项目名称 ====================== ...

  4. Linux关闭Tomcat为什么要用Kill,而不是shutdown.sh

    Linux关闭Tomcat为什么要用Kill,而不是shutdown.sh >>>>>>>>>>>>>>>&g ...

  5. openjdk源码阅读

    http://rednaxelafx.iteye.com/blog/1549577 http://blog.csdn.net/fancyerii/article/details/7007503 ├—a ...

  6. Fragment切换问题

    片断一: add hind @Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) { switch (check ...

  7. C++ template —— trait与policy类(七)

    第15章 trait与policy类---------------------------------------------------------------------------------- ...

  8. .net垃圾收集机制【转】

    在.NET Framework中,内存中的资源(即所有二进制信息的集合)分为"托管资源"和"非托管资源".托管资源必须接受.NET Framework的CLR( ...

  9. IOS设计模式第五篇之装饰设计模式的代理设计模式

    版权声明:原创作品,谢绝转载!否则将追究法律责任. 代理: 另一个装饰设计模式,代理,是一个代表或者协调另一个对象的行为机制.例如当你用一个tableView,你必须实现他里面的一个tableView ...

  10. django进阶-modelform&admin action

    先看效果图: 登陆admin后的界面: 查看作者: 当然你也可以定制admin, 使界面更牛逼 数据库表结构: app01/models.py from django.db import models ...