如果列为空,则 DynamicReports 删除行
DynamicReports remove row if column is null
这么简单的问题我有点卡住了。我正在使用 DynamicReports,如果列值为 null,我想隐藏整行。据我所知,DynamicReports 基于 JasperReports,可以通过选中 TextField 的选项“Remove line when blank”来实现。我怎样才能在动态中做到这一点?
我使用的组件:
TextColumnBuilder, ColumnGroupBuilder, JasperReportBuilder
如果我的任何 TextColumns 为空,我想隐藏整行。
好的,经过一番思考,我发现这个问题可以通过其他方式解决。
我们将使用列、组等 属性 setPrintWhenExpression(DRIExpression expression)
1. 创建class,它将处理、打印或不打印该行。 Dynamic 具有执行此操作的摘要 class:
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)
returns true.
,则打印列值
我还添加了字段 fieldName
,由于 其他 列状态,它允许我打印(或不打印)列。
2. 将 属性 添加到您的
列:
setPrintWhenExpression(DRIExpression expression)
组:
.setPrintSubtotalsWhenExpression(DRIExpression expression)
或
setFooterPrintWhenExpression(DRIExpression expression)
或
setHeaderPrintWhenExpression(DRIExpression expression)
取决于你想隐藏什么。
示例:
我们的报告中有 2 列:Product 和 ProductCount 列。如果 ProductCount 为 null(我们没有此产品的信息),我想隐藏 Product 列。
因此,为此,我会将 属性 PrintWhenExpression
添加到产品列
TextColumnBuilder<String> productColumn = col.column("Product", "Product", type.stringType())
.setPrintWhenExpression(new ShowExpressionDynamicReports("ProductCount"));
这么简单的问题我有点卡住了。我正在使用 DynamicReports,如果列值为 null,我想隐藏整行。据我所知,DynamicReports 基于 JasperReports,可以通过选中 TextField 的选项“Remove line when blank”来实现。我怎样才能在动态中做到这一点?
我使用的组件:
TextColumnBuilder, ColumnGroupBuilder, JasperReportBuilder
如果我的任何 TextColumns 为空,我想隐藏整行。
好的,经过一番思考,我发现这个问题可以通过其他方式解决。
我们将使用列、组等 属性 setPrintWhenExpression(DRIExpression expression)
1. 创建class,它将处理、打印或不打印该行。 Dynamic 具有执行此操作的摘要 class:
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)
returns true.
我还添加了字段 fieldName
,由于 其他 列状态,它允许我打印(或不打印)列。
2. 将 属性 添加到您的
列:
setPrintWhenExpression(DRIExpression expression)
组:
.setPrintSubtotalsWhenExpression(DRIExpression expression)
或
setFooterPrintWhenExpression(DRIExpression expression)
或
setHeaderPrintWhenExpression(DRIExpression expression)
取决于你想隐藏什么。
示例:
我们的报告中有 2 列:Product 和 ProductCount 列。如果 ProductCount 为 null(我们没有此产品的信息),我想隐藏 Product 列。
因此,为此,我会将 属性 PrintWhenExpression
添加到产品列
TextColumnBuilder<String> productColumn = col.column("Product", "Product", type.stringType())
.setPrintWhenExpression(new ShowExpressionDynamicReports("ProductCount"));