Easyui分页调整页面数据个数时不能实现分页详解

问题描述


当调整数据个数时


不能实现分页 下面就是实现分页的效果


action代码


private int page; // 第几页  
	private int rows; // 行数  
	
	
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
//查询全部用户  fenye
public String select(){
	List<UserBean> listUser = userService.Select(page,rows);
	//得到总页数
	int all = userService.all();
	if(listUser!=null) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();
		   jsonMap.put("total",all);// total键 存放总记录数,必须的
           jsonMap.put("rows", listUser);// rows键 存放每页记录 list
		//格式化分页数据***  必须的
	   result = JSONObject.fromObject(jsonMap);
		}
	return SUCCESS;
} 


daoImpl代码

@Override
	public List<UserBean> Select(int page,int rows) {
		int num = (page - 1) * rows;
		Object excute = hibernate.execute(new HibernateCallback() {
			@Override
			public Object doInHibernate(Session session) throws HibernateException {
				Query query = session.createQuery("from UserBean");
				query.setFirstResult(num);
				query.setMaxResults(rows);
				List list = query.list();
				return list;
				
			}
		});

		return (List<UserBean>) excute;
	}

js代码

$(function() { 
		$("#tt").datagrid({
			pageSize : 2,//每页显示的记录条数,默认为5  
			pageList : [ 2,5,10, 15, 20 ],//可以设置每页记录条数的列表
			  beforePageText: '第',//页数文本框前显示的汉字   
			     afterPageText: '页    共 {pages} 页',  
			     displayMsg: '第{from}到{to}条,共{total}条',  

			     
			     columns: [[
			                {
	                           title: '序号', field: 'u_id',halign: 'center',align: 'center',width:100,id:'typ',
			                },
			                {
	                            title: '用户名称', field: 'u_name',halign: 'center',align: 'center',width:100,
			                },
			                {
	                            title: '用户密码', field: 'u_pwd',halign: 'center',align: 'center',width:100,
			                },
			                {
	                            title: '性别', field: 'u_sex',halign: 'center',align: 'center',width:100,
			                },
			                {
	                            title: '邮箱', field: 'u_mail',halign: 'center',align: 'center',width:100,
			                },
			                {
	                            title: '自我介绍', field: 'u_describe',halign: 'center',align: 'center',width:100,
			                },
			                {
	                             title: '操作',field: 'action',halign: 'center',align: 'center',width: 200,
	                             formatter: function (value,row,index) {
	                                 if (row.editing == true) {
	                                     return "<a href='#' οnclick='saveRow(" + index + ");'>确定</a>  <a href='#' οnclick='reDo(" + index + ");'>取消</a>";
	                                 }
	                                 else {
	                                     return "<a href='#'  οnclick='return deleteRow();'>删除</a>";
	                                 }
	                             }
	                         }
	                ]],
		});	 
});

body代码


<body>
	<center>
		<h2>用户列表</h2>
		<table id="tt" class="easyui-datagrid"
			style="width: 835px; height: 250px" title="用户列表"
			data-options="rownumbers:true,singleSelect:true,pagination:true,url:'selectUser',method:'get'">
			<!--要想显示分页控件,pagination属性必须为true  -->
		</table>
	</center>
</body>


struts2代码


	<!-- 查询全部用户信息 -->
		<action name="selectUser" class="useraction" method="select">
		<result type="json">
		<param name="root">result</param>
		</result>
		</action>

实现的效果图为



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值