当前位置: 代码迷 >> Web前端 >> gridpanel 分页有关问题
  详细解决方案

gridpanel 分页有关问题

热度:620   发布时间:2012-10-29 10:03:53.0
gridpanel 分页问题
gridpanel分页问题困惑我一段时间了,参考了很多文档但遇到的问题还是很多主要有:
1、机制问题,extjs分页的机制是向后台传送两个参数start,limit,start是数据开始的地方,limit是每页的大小,所以说limit设定好以后一般情况是不变的。比方说每页两条数据的话,第一次start=0 limit=2第二次start=2 limit=2,开始我的理解是有错误的
2、数据库的问题。我才用的是ssh+extjs+access的模式,在dao层用到的是spring提供的hibernatetemplate的findByExample(entity,start,limit),的方法,发现无法执行,这个问题没有很好地解决,后台sql语句用到的是select ..from .. where recon>?我猜想access不支持这种模式,解决的方法是把数据查询出来以后对list结果集,采用sublist(start,start+limit)的方法获得。
3、totalPoperty的属性一定要配置。
4、对最后一页的处理,后台要进行对应的判断,不然前台显示不正常。
能回忆得这么多了
extjs代码
SavedPanel = Ext.extend(Ext.Panel,{
savedGrid:null,
constructor:function() {
this.savedGrid = new SaveGridPanel();
SavedPanel.superclass.constructor.call(this,{
renderTo:"savedpanel",
frame:true,
width:800,
height:300,
items:[this.savedGrid]

});
}
});
/****************************************************************************************************/
SaveGridPanel = Ext.extend(Ext.grid.GridPanel,{
mystore:null,
constructor:function() {
this.mystore = new SavedStore();
SaveGridPanel.superclass.constructor.call(this,{
store:this.mystore,
/*new Ext.data.JsonStore({
autoDestroy:true,
autoLoad:true,
url:"http://139.28.96.10:8080/premanagement3/secure/findDocuments!findDocument",
storeId:"documentGrid",
root:"documents",

fields:[{
name:"title",
mapping:"title"
},{
name:"dtime",
mapping:"dtime"
},{
name:"person",
mapping:"person.name"
},{
name:"department",
mapping:"person.department.name"
}]
}),*/
colModel:new Ext.grid.ColumnModel({
defaults:{
width:120,
sortable:true
},
columns:[{
header:"主题",
dataIndex:"title"
},{
header:"申请人",
dataIndex:"person"
},{
header:"部门",
dataIndex:"department"
},{
header:"时间",
dataIndex:"dtime"
}]
}),
viewConfig:{
forceFit:true
},
sm:new Ext.grid.RowSelectionModel({singleSelect:true}),
width:600,
height:200,
frame:true,
title:"已保存的申请",

bbar:new Ext.PagingToolbar({
store:this.mystore,
pageSize:2,
displayInfo:true,
displayMsg:"第{0}条到{1}条,一共{2}条"

})
});

}
});
/***************************************************************************************************************/
SavedStore = Ext.extend(Ext.data.JsonStore,{
constructor:function() {
SavedStore.superclass.constructor.call(this,{
proxy:new Ext.data.HttpProxy({method:"GET",
url:"http://139.28.96.10:8080/premanagement3/secure/findDocuments!findDocument"
}),
autoLoad:{params:{start:0,limit:2}},

storeId:"documentGrid",
root:"documents",
totalProperty:"total",
fields:[{
name:"title",
mapping:"title"
},{
name:"dtime",
mapping:"dtime"
},{
name:"person",
mapping:"person.name"
},{
name:"department",
mapping:"person.department.name"
}]
});
}
});

action层代码
package com.clds.action;

import java.util.List;
import java.util.Map;

import com.clds.model.Document;
import com.clds.model.Person;
import com.clds.service.DocumentService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class DocumentAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private Document document;
private List<Document> documents;
private DocumentService documentService;
private Boolean success;
private int start;
private int limit;
private int total;

public DocumentAction() {

}

@Override
public String execute() throws Exception {
/**//*System.out.println(this.document.getDtext());
System.out.println(this.document.getDtime());
System.out.println(this.document.getTitle());
System.out.println(this.document.getPerson().getId());
*/
this.documentService.saveDocument(document);
this.success = true;
return SUCCESS;
}
public String findDocument() throws Exception {
Map session = ActionContext.getContext().getSession();
Person person = (Person)session.get("users");
int departmentId = (Integer)session.get("departmentId");
this.document = new Document();
this.document.setDepartmentid(departmentId);
List<Document> d= this.documentService.findDocuments(document,start,limit);
this.total = d.size();
System.out.println(this.total);
System.out.println(d.isEmpty());
int maxResult = 0;
if ((start+limit)<total) {
maxResult = start+limit;
}else {
maxResult = total;
}
this.documents = d.subList(start, maxResult);

return SUCCESS;

}

public Document getDocument() {
return document;
}
public void setDocument(Document document) {
this.document = document;
}
public DocumentService getDocumentService() {
return documentService;
}
public void setDocumentService(DocumentService documentService) {
this.documentService = documentService;
}

public Boolean getSuccess() {
return success;
}

public void setSuccess(Boolean success) {
this.success = success;
}

public List<Document> getDocuments() {
return documents;
}

public void setDocuments(List<Document> documents) {
this.documents = documents;
}



public int getTotal() {
return total;
}

public void setTotal(int total) {
this.total = total;
}

public int getStart() {
return start;
}

public void setStart(int start) {
this.start = start;
}

public int getLimit() {
return limit;
}

public void setLimit(int limit) {
this.limit = limit;
}







}