六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 49|回复: 0

jquery+struts2.0分页

[复制链接]

升级  58%

5

主题

5

主题

5

主题

童生

Rank: 1

积分
29
 楼主| 发表于 2013-1-29 07:49:20 | 显示全部楼层 |阅读模式
最近要写一个分页的功能,找了很多的ajax分页资料,都觉得不是很好,本来想用ext的,可是觉得速度有点慢,在加上公司明确要求用jquery+json 实现分页,没办法,后来发现jquery的flexgrid的分页还不错。就花了点时间写了个。
 
 java 代码:
 @Controller
public class InfoIssueAction extends PBaseAction {
 public InfoIssueAction(){};
 @Autowired
 InfoIssueService infoIssueService;
 List rows=new ArrayList();
 protected int rp;
 protected int page=1;
 protected int total;
 
 @SuppressWarnings("unchecked")
 public String showInfoIssue(){
  int startIndex = (page - 1) * rp;     //计算查询开始数据下标       
  total=infoIssueService.getAllInfoIssue().size();
  List list=infoIssueService.getInfoIssue(startIndex, rp);
  for (Iterator iterator = list.iterator(); iterator.hasNext();) {
   InfoIssue infoissue = (InfoIssue) iterator.next();
     Map cellMap = new HashMap(); 
     cellMap.put("issueid", infoissue.getIssueid());
     cellMap.put("cell", new Object[] {infoissue.getIssueid(),infoissue.getCaption(),
       infoissue.getAttribute(),infoissue.getMaketop(),infoissue.getIssued()});
     rows.add(cellMap);
   
  }
  return "listSuccess";
 }

 @JSON(name="rows")
 public List getRows() {
  return rows;
 }
 public void setRows(List rows) {
  this.rows = rows;
 }
 public int getRp() {
  return rp;
 }
 public void setRp(int rp) {
  this.rp = rp;
 }
 public int getPage() {
  return page;
 }

 public void setPage(int page) {
  this.page = page;
 }

 public int getTotal() {
  return total;
 }
 public void setTotal(int total) {
  this.total = total;
 }
}
 
 
jsp代码:
需要导入文件,:
<link rel="stylesheet" type="text/css" href="grid/css/flexigrid/flexigrid.css"></link>
<script type="text/javascript" src="page/js/jquery.js"></script>
<script type="text/javascript" src="page/grid/flexigrid.js"></script>
 
<div class="bborderx">
<table id="flex1" style="display:none"></table>
</div>
 
js代码:
$("#flex1").flexigrid
   (
   {
   url: 'infoIssue/InfoIssue!show.action',
   dataType: 'json',
   colModel : [
    {display: '编号', name : 'issueid', width : 60, sortable : true, align: 'center'},
    {display: '标题', name : 'caption', width : 120, sortable : true, align: 'left'},
    {display: '是否置顶', name : 'maketop', width : 120, sortable : true, align: 'left'},
    {display: '是否发布', name : 'issued', width : 120, sortable : true, align: 'left'}
    ],
   buttons : [
    {name: '增加', bclass: 'add', onpress : test},
    {name: '删除', bclass: 'delete', onpress : test},
    {separator: true}
    ],
   searchitems : [
    {display: '标题', name : 'caption', isdefault: true}
    ],
   sortname: "issueid",
   sortorder: "asc",
   usepager: true,
   title: '新闻发布 ',
   useRp: true,
   rp: 1,
   showTableToggleBtn: true,
   width: 600,
   height: 300
   }
   );
   function test(com,grid)
   {
    if (com=='删除')
     {
         confirm('是否删除这 ' + $('.trSelected',grid).length + ' 条记录吗?')
     }
    else if (com=='增加')
     {
      alert('增加一条!');
     }   
   }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表