基于jqGrid实现列表分页效果(后台处理以及pageBean)

来源:互联网 发布:巨库软件 编辑:程序博客网 时间:2024/05/21 01:43

基于jqGrid实现列表分页效果(后台处理)

目录

[TOC]

分页实现布局:

  • 前端使用jqGrid配置实现分页展示

  • 后台创建分页javaBean

  • 后台handler实现分页


前端使用jqGrid配置实现分页展示

jqGrid实现列表的展示功能,通过配置实现分页查询, —— [ jqGrid参考资料 ]

代码块

jsonReader: {/* rows: 后台返回数据list集合   currPage: 当前页   totalpages: 总页数   totalCount: 总记录数*/      root:"rows", page:"currPage", total:"totalpages",          //   很重要 定义了 后台分页参数的名字。    records:"totalCount", repeatitems:false, id : "id"            }

后台创建分页pageBean

代码块

package com.kingdee.eas.custom.database.certificate;public class CertificateQueryPage {    private int curPage =1; //当前页    private int totalPage; // 总页数    private int totalCount; // 总行数    private int pageSize=20; // 每页行数    public CertificateQueryPage(int rows, Integer curPage,Integer pageSize){        this.totalCount = rows;        this.curPage = curPage;        this.pageSize=pageSize;        if(this.totalCount % this.pageSize ==0){            this.totalPage = this.totalCount/this.pageSize;        }else if (rows < this.pageSize){            this.totalPage =1;        }else{            this.totalPage = this.totalCount/this.pageSize +1;        }    }    public CertificateQueryPage(int rows) {        this.totalCount=rows;        if(this.totalCount % this.pageSize ==0){            this.totalPage =this.totalCount/this.pageSize;        }else if(rows < this.pageSize){            this.totalPage=1;        }else {            this.totalPage =this.totalCount/this.pageSize +1;        }    }    public int getCurPage() {        return curPage;    }    public void setCurPage(int curPage) {        this.curPage = curPage;    }    public int getTotalPage() {        return totalPage;    }    public void setTotalPage(int totalPage) {        this.totalPage = totalPage;    }    public int getTotalCount() {        return totalCount;    }    public void setTotalCount(int totalCount) {        this.totalCount = totalCount;    }    public int getPageSize() {        return pageSize;    }    public void setPageSize(int pageSize) {        this.pageSize = pageSize;    }}

后台handler实现分页

代码块

    // 分頁        String page = request.getParameter("page");        String pageSizeR = request.getParameter("rows");        CertificateQueryPage queryPage =null;        if(!StringUtils.isEmpty(page) || !StringUtils.isEmpty(pageSizeR)){            queryPage = new CertificateQueryPage(dataList.size(),Integer.valueOf(page),Integer.valueOf(pageSizeR));        }else{            queryPage = new CertificateQueryPage(dataList.size());        }        //CertificateQueryPage         int pageSize = queryPage.getPageSize();        int curPage = queryPage.getCurPage();        int fromIndex =(curPage -1)*pageSize;//开始索引        int toIndex = curPage*pageSize;// 结束索引        if(toIndex> queryPage.getTotalCount()){// 如果结束索引大于list的size,则结束索引等于lise的size            toIndex =queryPage.getTotalCount();        }        if(fromIndex > toIndex){// 如果开始索引大于结束索引,则            fromIndex=0;        }        // dataList为数据总量,这里通过subList函数返回分页结果数据        // gridDataMap 为后台返回前端的Map gridDataMap = new LinkedHashMap()数据集;这里使用LinkedHashMap的目的,保证数据排序前后端不混乱        List list = dataList.subList(fromIndex, toIndex);        gridDataMap.put("rows", list);        gridDataMap.put("currPage", curPage);        gridDataMap.put("totalpages", queryPage.getTotalPage());        gridDataMap.put("totalCount", queryPage.getTotalCount());

原创粉丝点击