我用extjs分页时,基本能运行了。但有个地方一直出错,每页13条记录,当最后一页不足13条时,最后一页没法显示,估计是代码有问题,后台用struts2做的,望高手指点。
这是extjs前台部分代码var studentGrid = new Ext.grid.GridPanel({
frame:true,
autoHeight:true,
store : studentStore,
cm : studentCm,
viewConfig : {
forceFit : true
},
stripeRows:true,
loadMask:{
msg:'正在加载数据,请稍后...'
},
bbar:new Ext.PagingToolbar({
pageSize:13,
store:studentStore,
displayInfo:true,
displayMsg:'显示第 {0} 条到 {1} 条的记录, 一共 {2} 条',
emptyMsg:'没有记录'
})
});
studentStore.load({params:{start:0,limit:13}});这是后台Action代码public String query(){
userDao=new UserDaoImp();
List<User> users=userDao.getUsers("Student");
Iterator it=users.iterator();
while(it.hasNext()){
studentList.add((Student)it.next());
}
totalCount=userDao.findAllRows("Student");
JSONArray jarray=JSONArray.fromObject(studentList.subList(this.getStart(),this.getStart()+this.getLimit()));
json="{totalCount:"+this.getTotalCount()+",start:"+this.getStart()+",limit:"+this.getLimit()+",root:"+jarray.toString()+"}";
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/json;charset=UTF-8");
try {
PrintWriter out = response.getWriter();
out.write(json);
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
这是extjs前台部分代码var studentGrid = new Ext.grid.GridPanel({
frame:true,
autoHeight:true,
store : studentStore,
cm : studentCm,
viewConfig : {
forceFit : true
},
stripeRows:true,
loadMask:{
msg:'正在加载数据,请稍后...'
},
bbar:new Ext.PagingToolbar({
pageSize:13,
store:studentStore,
displayInfo:true,
displayMsg:'显示第 {0} 条到 {1} 条的记录, 一共 {2} 条',
emptyMsg:'没有记录'
})
});
studentStore.load({params:{start:0,limit:13}});这是后台Action代码public String query(){
userDao=new UserDaoImp();
List<User> users=userDao.getUsers("Student");
Iterator it=users.iterator();
while(it.hasNext()){
studentList.add((Student)it.next());
}
totalCount=userDao.findAllRows("Student");
JSONArray jarray=JSONArray.fromObject(studentList.subList(this.getStart(),this.getStart()+this.getLimit()));
json="{totalCount:"+this.getTotalCount()+",start:"+this.getStart()+",limit:"+this.getLimit()+",root:"+jarray.toString()+"}";
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/json;charset=UTF-8");
try {
PrintWriter out = response.getWriter();
out.write(json);
out.flush();
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
我用ExtJs一年多来怎么没有发现这个问题呀</script>
</head>
<script type="text/javascript">
Ext.onReady(function() {
var _url = '<%=basePath%>/com.lxitedu.chinaMobile.wwwManage.action/queryLognote';
var checkbox = new Ext.grid.CheckboxSelectionModel({});
var rowNumber = new Ext.grid.RowNumberer();
var colM = [rowNumber,checkbox,{header:'序 列 号',dataIndex:'id',sortable:true,align:'center'},
{header:'用 户 名',dataIndex:'userName',sortable:true,align:'center'},
{header:'登 录 IP',dataIndex:'userip',sortable:true,align:'center'},
{header:'登录日期',dataIndex:'logindate',sortable:true,align:'center'},
{header:'登录状态',dataIndex:'loginstate',sortable:true,align:'center'}];
var store = new Ext.data.Store( {
url :_url,
method:'POST',
baseParams:{limit:10,start:0},
reader: new Ext.data.JsonReader(
{
root:'result',
totalProperty:'totalCount'
},
Ext.data.Record.create([
{name:'id',mapping:'id'},
{name:'userName',mapping:'userName'},
{name:'userip',mapping:'userip'},
{name:'logindate',mapping:'logindate'},
{name:'loginstate',mapping:'loginstate'}
])
),
autoLoad:true
});
var pagging = new Ext.PagingToolbar( {
store : store,
pageSize : 10,
displayInfo : true,
displayMsg : '显示第{0}条到{1}条记录,一共{2}条'
});
var config = {
title:'日志查询',
width:560,
height:330,
id:'grid',
frame:true,
renderTo: 'mainDiv',
columns:colM,
sm:checkbox,
store:store,
bbar:pagging,
tbar:["->",
{text:'删除',handler:del}
]
};
var grid = new Ext.grid.GridPanel(config);
function del(){
var record = grid.getSelectionModel().getSelections();
if(record.length != 0){
for(var i = 0;i<record.length;i++){
Ext.Ajax.request({
url:'<%=basePath%>/com.lxitedu.chinaMobile.wwwManage.action/deleteLognote',
method:'POST',
success:function(action,response){
location.href='queryLognote.jsp';
},
params:{
'lognoteForm.id':record[i].get('id')
}
});
}
}else {
alert("请选择要删除的行");
}
}
});
</script>
这是我写的代码基本上一致呀,你们看看那里不对的地方我们共同讨论