extjs的grid实现分页查看功能
2012-02-02 13:04
603 查看
1.定义store
3. store执行load()操作时,传入参数
4.在后台的action类里写上如下对象,注意要添加getter and setter。student()是struts2对应的method
5.service层里的getPageService()返回查询值反馈到page
6.dao层代码
//-------------学生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; }
相关文章推荐
- EXTJS Grid数据显示、翻页、增删改查功能实现
- ExtJs Grid分页时序号自增的实现
- EXTJS Grid数据显示、翻页、增删改查功能实现
- extjs中如何创建一个带分页功能的Ext.grid.GridPanel
- EXTJS Grid数据显示、翻页、增删改查功能实现
- Extjs 查询出用户,实现增删改查功能 (重点在于查询后替换和分页问题)
- EXTJS Grid数据显示、翻页、增删改查功能实现
- ExtJs4 SpringMvc3 实现Grid 分页
- EXTJS Grid数据显示、翻页、增删改查功能实现
- [转]ExtJS Grid 分页时保持选中的简单实现方法
- 解决grid选中行分页后不保持的问题(实现分页多选记忆功能)
- EXTJS Grid数据显示、翻页、增删改查功能实现
- EXTJS4.x之grid(2)--实现添加用户功能
- 与ASP.NET服务器端结合返回JSON数据实现ExtJS GridPanel客户端分页
- EXTJS Grid数据显示、翻页、增删改查功能实现
- [Extjs] Ext4 Ext.grid.Panel 分页实现(mybatis 分页插件-PageHelper 使用)
- ExtJs Grid分页时序号自增的实现
- EXTJS Grid数据显示、翻页、增删改查功能实现
- 04-UIScrollView分页功能实现循环查看图片
- 使用ExtJs 来显示数据,并实现数据的分页功能