欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JSP+EXt2.0实现分页的方法

程序员文章站 2022-05-18 12:49:40
本文实例讲述了jsp+ext2.0实现分页的方法。分享给大家供大家参考。具体如下: javascript代码: ext.onready(function(){...

本文实例讲述了jsp+ext2.0实现分页的方法。分享给大家供大家参考。具体如下:

javascript代码:

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); 
%>

希望本文所述对大家的jsp程序设计有所帮助。