+ -
当前位置:首页 → 问答吧 → Ext中的分页问题

Ext中的分页问题

时间:2010-11-03

来源:互联网

Ext.onReady(function(){
var cm=new Ext.grid.ColumnModel([
{header:'用户编号',width: 60,sortable:true,resizable:false,dataIndex:'userid'},
{header:'用户名',width: 100,sortable:true,resizable:false,dataIndex:'username'},
{header:'邮箱',width: 150,sortable:true,resizable:false,dataIndex:'email'},
{header:'用户年龄',width: 60,sortable:true,resizable:false,dataIndex:'userage'},
{header:'用户生日',width: 100,sortable:true,resizable:false,dataIndex:'birthday'},
{header:'用户余额',width: 60,sortable:true,resizable:false,dataIndex:'money'}
]);

var proxys= new Ext.data.HttpProxy({url: "fenyeshuju.jsp"});
/*var users = Ext.data.Record.create([
{name: "userid", type: "int"},
{name: "username", type: "string"},
{name: "email", type: "string"},
{name: "userage", type: "string"},
{name: "birthday", type: "date"},
{name: "money", type: "double"}
]);*/
var readers = new Ext.data.JsonReader({
totalProperty : "totalProperty",
root : "root"
}, [
{name: 'userid'},
{name: 'username'},
{name: 'email'},
{name: 'userage'},
{name: 'birthday'},
{name: 'money'}
]);
var store = new Ext.data.Store({
proxy : proxys,
reader : readers
});
store.load({params: {start: 0, limit: 5}});

var grid = new Ext.grid.GridPanel({
  title:"用户信息展示",
  renderTo:'aa',
autoHeight : true,
loadMask:true,
colModel:cm,
store:store,
viewConfig:{forceFit:true},
bbar:new Ext.PagingToolbar({
pageSize:5,
store:store,
displayInfo:true,
displayMsg:'显示第{0}条到{1}条记录,一共{2}条',
emptyMsg:"没有记录"
})

});

});

jsp页面:
<%
request.setCharacterEncoding("GBK");
response.setCharacterEncoding("GBK");
int start=Integer.parseInt(request.getParameter("start")) ;
int limit=Integer.parseInt(request.getParameter("limit")) ;
int end =start+limit;

UserBiz userBiz=new UserBiz();
int totalProperty=userBiz.getAll().size();
if(end>totalProperty){
end=totalProperty;
}
List<Users>list= userBiz.page(start,limit);
try{
String json="{totalProperty:"+totalProperty+",root:[";
for(int i=0;i<list.size();i++){
json+="{userid:"+list.get(i).getUserid()+",username:'"+list.get(i).getUsername()
+"',email:'"+list.get(i).getEmail()+"',userage:"+list.get(i).getUserage()+",birthday:'"+
list.get(i).getBirthday()+"',money:"+list.get(i).getMoney()+"}";
if(i!=list.size()-1){
json+=",";
}
}
json+="])";
System.out.println(json);
response.getWriter().write(json);
}catch(Exception e) {
e.printStackTrace();
}

%>

后台可以打印出JSON格式的数据 :
{totalProperty:22,root:[
{userid:1,username:'xiaoxin',email:'[email protected]',userage:20,birthday:'1990-08-10 00:00:00.0',money:50.0},
{userid:2,username:'xsn',email:'[email protected]',userage:20,birthday:'1990-08-10 00:00:00.0',money:50.0},
{userid:3,username:'xs22n',email:'[email protected]',userage:20,birthday:'1990-08-10 00:00:00.0',money:50.0},
{userid:4,username:'xs2wn',email:'[email protected]',userage:19,birthday:'1991-08-10 00:00:00.0',money:50.0},
{userid:5,username:'xsfn',email:'[email protected]',userage:19,birthday:'1991-01-10 00:00:00.0',money:50.0}
]
)}

到展示页面也可以看到Grid控件 就是里面不出数据  

求解!!!

作者: ct460864589   发布时间: 2010-11-03

JScript code

{totalProperty:22,root:[
{userid:'1',username:'xiaoxin',email:'[email protected]',userage:'20',birthday:'1990-08-10 00:00:00.0',money:'50.0'},
{userid:'2',username:'xsn',email:'[email protected]',userage:'20',birthday:'1990-08-10 00:00:00.0',money:'50.0'},
{userid:'3',username:'xs22n',email:'[email protected]',userage:'20',birthday:'1990-08-10 00:00:00.0',money:'50.0'},
{userid:'4',username:'xs2wn',email:'[email protected]',userage:'19',birthday:'1991-08-10 00:00:00.0',money:'50.0'},
{userid:'5',username:'xsfn',email:'[email protected]',userage:'19',birthday:'1991-01-10 00:00:00.0',money:'50.0'}
]
)}



作者: leehuat   发布时间: 2010-11-04

json userid:1,username:'xiaoxin',email:'[email protected]',userage:20,birthday:'1990-08-10 00:00:00.0',money:50.0},
这里面返回全部是字符串试试!

作者: leehuat   发布时间: 2010-11-04

{totalProperty:22,root:[
{userid:'1',username:'xiaoxin',email:'[email protected]',userage:'20',birthday:'1990-08-10 00:00:00.0',money:'50.0'},
{userid:'2',username:'xsn',email:'[email protected]',userage:'20',birthday:'1990-08-10 00:00:00.0',money:'50.0'},
{userid:'3',username:'xs22n',email:'[email protected]',userage:'20',birthday:'1990-08-10 00:00:00.0',money:'50.0'},
{userid:'4',username:'xs2wn',email:'[email protected]',userage:'19',birthday:'1991-08-10 00:00:00.0',money:'50.0'},
{userid:'5',username:'xsfn',email:'[email protected]',userage:'19',birthday:'1991-01-10 00:00:00.0',money:'50.0'}
]
)}

最后是不是多了一个)这个符号。

作者: licip   发布时间: 2010-11-04

JScript code
{totalProperty:22,root:[
{userid:1,username:'xiaoxin',email:'[email protected]',userage:20,birthday:'1990-08-10 00:00:00.0',money:50.0},
{userid:2,username:'xsn',email:'[email protected]',userage:20,birthday:'1990-08-10 00:00:00.0',money:50.0},
{userid:3,username:'xs22n',email:'[email protected]',userage:20,birthday:'1990-08-10 00:00:00.0',money:50.0},
{userid:4,username:'xs2wn',email:'[email protected]',userage:19,birthday:'1991-08-10 00:00:00.0',money:50.0},
{userid:5,username:'xsfn',email:'[email protected]',userage:19,birthday:'1991-01-10 00:00:00.0',money:50.0}
]
)}//多了)号,不要就可以了

作者: IBM_hoojo   发布时间: 2010-11-04

热门下载

更多