如下图所示,苍穹中报表列表上没有过滤,如何强制给报表加上列表过滤呢?
强制增加过滤实现方案
1、添加表单插件AbstractReportFormPlugin,重写setSortAndFilter方法
@Override
public void setSortAndFilter(List<SortAndFilterEvent> allColumns) {
super.setSortAndFilter(allColumns);
for(SortAndFilterEvent event : allColumns){
event.setSort(true);
event.setFilter(true);
}
}
2、添加查询插件AbstractReportListDataPlugin,重写query方法
@Override
public DataSet query(ReportQueryParam queryParam, Object o) throws Throwable {
DataSet dataSet = super.query(queryParam, o);
List<String> decimalPropertys = Arrays.asList("amount", "supperbillamount");
List<QFilter> filters = queryParam.getFilter().getHeadFilters();
for (QFilter filter : filters) {
if (decimalPropertys.contains(filter.getProperty())) {
Object value = filter.getValue();
if (value instanceof String) {
String filterValueStr = (String)value;
filter.__setValue(new BigDecimal(filterValueStr));
}
}
}
StringBuilder sb = new StringBuilder();
if(filters.size()>0){
// DataSet ds=dataSet.filter(filters.get(0).toString());
for(int i=0;i<filters.size();i++){
QFilter q =filters.get(i);
sb.append(q.toString());
if(i!=filters.size()-1){
sb.append(" and ");
}
}
return dataSet.filter(sb.toString());
}else{
return dataSet;
}
}
最终效果:
推荐阅读