extjs的grid实现分页查看功能

1.定义store

//-------------学生grid--------------
		var studentStore = new Ext.data.JsonStore({
			url : 'studentInfo_student.action',
			root: 'studentList',
			fields: [
						'id',
			 			'name'
			 		],
			totalProperty : 'page.totalRows',
			baseParams : {
				limit : pageSize
			}
		})
2.定义grid

		var grid = new Ext.grid.EditorGridPanel({
			id : 'gird',
			title : '学生信息列表',
			region : 'center',
			stripeRows : true,
			autoScroll : true,
			loadMask : true,
			store : studentStore,
			clicksToEdit : 1,
			frame : true,
			cm : new Ext.grid.ColumnModel({
				defaults : {
					sortable : true
				// columns are not sortable by default           
				},
				columns : [ new Ext.grid.RowNumberer(),

				{
					header : '姓名',
					dataIndex : 'name',
					width : 100
				}, {
					header : '学号',
					dataIndex : 'id',
					width : 100
				}
				]
			}),

			bbar : new Ext.PagingToolbar({
				pageSize : pageSize,
				store : studentStore,
				displayInfo : true,
				displayMsg : '当前{0}到{1}条,共{2}条',
				emptyMsg : '没有符合条件的数据'		
			})
		})

3. store执行load()操作时,传入参数

{
						xtype : 'button',
						text : '查询',
						listeners : {
					          click : function () {
					        	  studentStore.load({
					      			params : {
					    				start : 0
					    			}
					    		});
					     	}
					    }

4.在后台的action类里写上如下对象, 注意要添加getter and setter。student()是struts2对应的method

	private int limit;
	private int start;
	private JSONObject page;
public String student(){
		page = this.studentInfoService.getPageService(start, limit);
		studentList=studentInfoService.getStudent( start, limit);
		success=true;
		failure=false;
		return SUCCESS;
	}

5.service层里的getPageService()返回查询值反馈到page

public 	JSONObject getPageService(int start,int limit){
		JSONObject json = new JSONObject();
		long totalRows = this.studentInfoDao.countStuInfo();
		int currentPage = start/limit+1;
		json.put("currentPage", currentPage);
		if(currentPage==1){
			json.put("firstPage", true);
		}else{
			json.put("firstPage", false);
		}
		json.put("getCount", true);
		long totalPages = totalRows/limit;
		if(totalRows%limit!=0){
			totalPages += 1;
		}
		if(currentPage==totalPages){
			json.put("lastPage", true);
		}else{
			json.put("lastPage", false);
		}
		json.put("pageSize", limit);
		json.put("startRow", start);
		json.put("totalPages", totalPages);
		json.put("totalRows", totalRows);
		return json;
	}

6.dao层代码

public List<Student> getStudentByPage(int start,int limit){
		Student s=new Student();
		List<Student> list=this.getHibernateTemplate().findByExample(s, start, limit);
		return list;
	}



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值