DynamicReports删除行如果列为空

DynamicReports删除行如果列为空

问题描述:

我有点卡住这样一个简单的问题。我正在使用DynamicReports,如果列值为空,我想隐藏整行。据我所知,DynamicReports基于JasperReports,可以通过检查TextField的选项“删除行,当空白”。我如何在Dynamic中做到这一点?DynamicReports删除行如果列为空

组件,我用:

TextColumnBuilder, ColumnGroupBuilder, JasperReportBuilder 

我想隐藏整行,如果我的任何TextColumns会是空的。

好的,经过一番思考,我发现这个问题可以通过其他方式解决。

我们要去使用列,组等财产setPrintWhenExpression(DRIExpression expression)

1.创建类,它将处理,打印或不打印该行。动态有这样做的抽象类:

public class ShowExpressionDynamicReports extends AbstractSimpleExpression<Boolean> { 

    private String fieldName; 

    public ShowExpressionDynamicReports(String fieldName) { 
     this.fieldName = fieldName; 
    } 

    @Override 
    public Boolean evaluate(net.sf.dynamicreports.report.definition.ReportParameters reportParameters) { 
     return reportParameters.getValue(fieldName) != null; 
     } 
    } 

你应该为了把它作为参数列如下方法来扩展AbstractSimpleExpression。

因此,如果evaluate(ReportParameters rp)返回true,则会打印列值。

我还添加了字段fieldName它允许我打印(或不)列由于其他的列状态。

2.添加属性到您的

柱:

setPrintWhenExpression(DRIExpression expression)

组:

.setPrintSubtotalsWhenExpression(DRIExpression expression)

setFooterPrintWhenExpression(DRIExpression expression)

setHeaderPrintWhenExpression(DRIExpression expression)

取决于你想隐藏什么。

例子:

我们有2列在我们的报告:产品和ProductCount列。如果ProductCount为null(我们没有关于此产品的信息),我想隐藏Product列。

所以,要做到这一点,我会加属性PrintWhenExpression产品列

TextColumnBuilder<String> productColumn = col.column("Product", "Product", type.stringType()) 
.setPrintWhenExpression(new ShowExpressionDynamicReports("ProductCount"));