public String execute() throws Exception
{
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("utf-8");
List person = dao.getAllPage(start, 10);
//String json= ExtHelper.getJsonFormList(dao.getAllSize(), person);
String json = "{totalCount:"+dao.getAllSize()+",items:[";
for(int i =1;i<person.size();i++)
{
Person p = (Person)person.get(i);
json+="{'id':"+p.getId()+",'name':'"+p.getName()+"','age':"+p.getAge()+",'sex':'"+p.getSex()+"','birthday':'"+p.getBirthday()+"'}";
if(i!=getLimit()+start-1)
{
json+=",";
}
}
json += "]}";
response.getWriter().write(json);
System.out.println(json);
System.out.println("person size "+person.size()+"start:"+getStart()+"limit:"+getLimit());
return null;
}
var store = new Ext.data.Store({
reader:new Ext.data.JsonReader({
totalRecords:"results",
root:'items',
totalProperty: 'totalCount',
idProperty: 'threadid',
remoteSort: true,
fields:[
{name:'id'},
{name:'name'},
{name:'age'},
{name:'sex'},
{name:'birthday'}
]
}),
proxy:new Ext.data.HttpProxy({
url:'ext.action'
})
})
。。。
var pagingBar = new Ext.PagingToolbar({
pageSize: 10,
store: store,
emptyMsg: "没有记录"
});
// 创建grid对象显示数据
var cb = new Ext.grid.CheckboxSelectionModel();
var grid = new Ext.grid.GridPanel({
title:'人员列表',
el:'grid-div',
tbar:[toolbar,pagingBar],
frame:true,
store:store,
autoScroll:true,
width:860,
iconCls:'silk-user',
height:480,
collapsible: true,
animCollapse: true,
loadMask:{Msg:'请稍后...'},
viewConfig : {
autoFill : true
},
sm : cb,
columns:[
new Ext.grid.RowNumberer({
header : '行号',
width : 40
}),// 表格行号组件
cb,
{header:'id',width:10,dataIndex:'id',sortable:false},
{header:"姓名",width:80,dataIndex:'name',sortable:true},
{header:"年龄",width:80,dataIndex:'age',sortable:true},
{header:"性别",width:80,dataIndex:'sex',sortable:true},
{header:"生日",width:80,dataIndex:'birthday',sortable:true}
]
});
grid.render("grid-div");
store.load({params:{start:0, limit:10}});
extjs struts2分页
最新推荐文章于 2024-08-15 15:27:27 发布