修改jpivot源码实现分页

使用jpivot过程中,如果查询到的结果行数超过一个阈值,后面的显示就会丢失,这时需要分页显示。

假设应用中组装的MDX语句已经含有NON EMPTY,把空行直接过滤掉了。

这时需要修改的jpivot源码文件包括:

1、TableComponent.java

其中方法buildRows2Dim(Element)

  在方法的最后的else块中,代码如下:

...
cellElem.setAttribute("value", v);
cellElem.setAttribute("colspan", Integer.toString(nosColumns));
row.appendChild(cellElem);
} else {
    ResultCache resultCache = ResultCache.getInstance();
    int currentPage = 1;  //当前页数
    int pageRows = 100;  //每页多少行,默认100行
    if(resultCache.getResult("currentPage") != null) {
         currentPage = (Integer)resultCache.getResult("currentPage");
    }
    if(resultCache.getResult("pageRows ") != null) {
         pageRows = (Integer)resultCache.getResult("pageRows ");
    }
    if(pageRows % 2 != 0) {  //保证每页行数是偶数
       pageRows  += 1;
    }
    int i = 0;  //每页起始位置
    int end = 0;  //每页结束位置
    if(nosRows > pageRows ) {
        i = (currentPage - 1) * pageRows ;
        if(nosRows - i > pageRows) {
           end = i + 100;
        } else if(nosRows - i <= 0) {
              i = 0; 
              end = i + 100;
        } else {
              end = nosRows;
        }
    } else {
        end = nosRows;
    }
    for(; i < end; i++) {
         boolean even = (i % 2 == 0);
         Element row = append("row", parent);
         rowAxisBuilder.buildRow(row, i);
         buildCells(row, even);
    }
}    

其中使用到echache缓存了 当前页数 和 每页多少行  的值,从而进行计算需要显示结果,有关echache的使用参见http://www.cnblogs.com/hongxf1990/p/4534243.html

2、SpanCalc.java

其中方法makePosSpan(Span span, int hierSpans)

添加代码:

if(forcePositionBreak[pi][hi])
     break loop;

ResultCache resultCahe = ResultCache.getInstance();
int pageRows = 100;  //每页显示的行数
if(resultCahe.getResult("pageRows ") != null) {
    pageRows = resultCahe.getResult("pageRows");
}
if(pageRows % 2 == 0) {  //保证每行显示的是偶数
    pageRows += 1;
}
if(pi % pageRows == 0) {
  break loop;
} 

这里强制按照每页显示的行数进行分行

 

修改这两个java文件即可,这里其实就是把原本全部的行数按照需要分段显示在页面上

posted @ 2015-05-27 20:11  飞天0407  阅读(298)  评论(0编辑  收藏  举报