中国第一Ajax站长门户:www.okajax.com   虚拟主机 域名注册 云主机

EXt2.0 + jsp 分页 - okajax.com - Ajax中国

我要投稿 会员登陆 RSS订阅 本站推荐:
您的位置主页 > Ajax技术 > Ajax框架学习 > extjs > EXt2.0 + jsp 分页

EXt2.0 + jsp 分页

2008-07-28    文章来源:互联网    浏览次数:

Ext.onReady(function(){

var sm = new Ext.grid.CheckboxSelectionModel();

var cm = new Ext.grid.ColumnModel([
    new Ext.grid.RowNumberer(),
    sm,
        {header:'编号',dataIndex:'id',sortable:true},
        {header:'名称',dataIndex:'name',sortable:true},
        {header:'性别',dataIndex:'sex',sortable:true,renderer:function(value){
        if(value=='male'){
          return " <span style='color:red;font-weight:bold;'>红男 </span> <img src='./img/125.gif'>";
        }else{
          return " <span style='color:green;font-weight:bold;'>绿女 </span> <img src='./img/123.gif'>";
        }
        }},
        {header:'描述',dataIndex:'descn',sortable:true}
    ]);
    cm.defaultSortable = true;
 var ds = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({url:'page.jsp'}),
        reader: new Ext.data.JsonReader({
                totalProperty: 'totalProperty',
                root: 'root'
    },
    [
        {name: 'id',mapping:'id'},
        {name: 'name',mapping:'name'},
        {name:'sex',mapping:'sex'},
        {name: 'descn',mapping:'descn'}
    ]),
    remoteSort:true
   
    });
      
    var grid = new Ext.grid.GridPanel({
    el: 'grid',
    title:'Ext Grid Test',
    width:450,
    height:410,
    trackMouseOver:false,
   loadMask: {msg:'正在加载数据,请稍侯……'},
    store:ds,
    cm: cm,
    sm:sm,
    bbar: new Ext.PagingToolbar({
            pageSize: 5,
            store: ds,
            displayInfo: true,
            displayMsg: '当前显示 {0} - {1}条记录 /共 {2}条记录',
            emptyMsg: "No topics to display"
        })
});
 
    grid.render();
   
    ds.load({params:{start:0, limit:5}});
   
});

 

//JSP

<%@ page language="java" pageEncoding="UTF-8"%>
     <%
  String start = request.getParameter("start");
  String limit = request.getParameter("limit");

int index = Integer.parseInt(start);
  int pageSize = Integer.parseInt(limit);
  String json = "{totalProperty:100,root:[";
  String sex="";
  for (int i = index; i < pageSize + index; i++) {
  if(i%2==0)
  {
   sex="male";
  }
  else{
   sex="female";
  }
    json += "{id:" + i + ",name:'" + i + "',sex:'"+sex+"',descn:'descn" + i
    + "'}";
    if (i != pageSize + index - 1) {
    json += ",";
    }
  }
  json += "]}";
  response.getWriter().write(json);
  System.out.print(json);
  %>

文章评论(查看全部)

看不清楚?单击换一张。
loading.. 评论加载中....
关于我们 - 广告服务 - 版权隐私 - 免责声明 - RSS地图 - 网站地图 - 使用帮助 - 返回顶部