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

基于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());

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值