日期:2014-05-16 浏览次数:20281 次
Ext.onReady(function() { var pageSize = 5; var proxyData = new Ext.data.HttpProxy({url:'getJson'}); var render = new Ext.data.JsonReader({root:'data',totalProperty: 'totalCount'},[{ name : 'id', type : 'int' },{ name : 'name', type: 'string' },{ name : 'borth', type : 'date' }]); var ds = new Ext.data.Store({ proxy : proxyData, reader : render }); var cm = new Ext.grid.ColumnModel([ new Ext.grid.RowNumberer(), { header: '序号', dataIndex: 'id',width:15 }, { header: '姓名', dataIndex: 'name',width:30 }, { header: '生日', dataIndex: 'borth', width:55 , sortable: true, renderer: Ext.util.Format.dateRenderer('Y-m-d H:i:s') } ]); cm.defaultSortable = true; ds.load({params:{start:0,limit:pageSize}}); var grid = new Ext.grid.GridPanel({ loadMask : {msg:'正在加载数据,请稍等......'}, store: ds, layout:'fit', cm: cm, height:300, renderTo:Ext.getBody(), title:'<center>人员信息</center>', viewConfig: { forceFit: true }, bbar: new Ext.PagingToolbar({ pageSize: pageSize, store: ds, displayInfo: true, displayMsg: '当前显示{0} - {1}条,共{2}条数据', emptyMsg: "没有记录" }) }); });
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int start = Integer.valueOf(request.getParameter("start")); int limit = Integer.valueOf(request.getParameter("limit")); String jsonStr = null; Map<String, Object> jsonObj = new HashMap<String, Object>(); List<Person> persons = new ArrayList<Person>(); int totalCount = 20; for (int i = 1; i <= totalCount; i++) { Person p = new Person(i, "路人" + i, new Date()); persons.add(p); } persons = persons.subList(start, limit+start); jsonObj.put("data", persons); jsonObj.put("totalCount", totalCount); response.setContentType("application/x-json"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); Gson gson = new Gson(); jsonStr = gson.toJson(jsonObj); out.print(jsonStr); out.close(); }