在JasperReports中显示静态文本而不是空组 [英] Displaying static text instead of empty group in JasperReports

查看:458
本文介绍了在JasperReports中显示静态文本而不是空组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Jasper报告,显示了一个帐单行项目列表。这些项目按结算周期进行分组,然后按项目是收费还是信用分组。对于有收费但没有积分的结算周期,我想在该期间的信用组中显示一个静态文本字段,表示无信用。如何才能做到这一点?

I have a Jasper report that displays a list of bill line items. These items are grouped by billing period, and then by whether the item is a charge or credit. For billing periods in which there are charges but no credits, I would like to display a static text field stating "No credits" in the Credit group for that period. How can this be done?

编辑添加:这假设我使用的是数据源的SQL查询,而不是自定义数据源。如果我自定义我的数据源,我可以在到达报告之前处理预处理,但我希望找到一种方法来解决Jasper跳过没有符合组标准的行的组的行为。

Edited to add: This is assuming that I am using an SQL query for the data source, as opposed to customizing one. If I customize my data source, I can handle this in pre-processing before I reach the report, but I was hoping to discover a way to get around Jasper's behavior of skipping groups with no rows meeting the group criteria.

推荐答案

如果您能够在数据源中计算每个组的总信用额度,那么您可以在静态文本上使用'print when expression'属性。例如:

If you were able to, in your data source, have a count of total # of credits for each group, then you could use the 'print when expression' property on the static text. e.g:

new Boolean ($F{total_credits}.equals(0));

静态文本需要放在组页眉或页脚中,因为它不能在组详细信息部分(它会打印多次)。

The static text would need to go in the group header or footer as it wouldn't work in the group detail section (it would print out multiple times).

您可能需要创建变量而不是使用 $ F {total_credits} 直接 - 我不确定JasperReports如何处理访问组页脚中的字段。您可能还会发现在组标题中它会选择正确的total_credits,而在组页脚中却没有。

You may need to create a variable instead of use $F{total_credits} directly - I'm not certain how JasperReports deals with accessing fields in group footers. You may also find that in the group header it picks up the correct total_credits while in the group footer it doesn't.

另一种方法是拥有一个变量计算组中的总信用额度。您需要将变量的重置类型设置为组,然后设置重置组。变量表达式如下所示:

The other way would be to have a variable that counts the total # of credits in the group. You would need to set the 'reset type' for the variable to 'group', then set the reset group. The Variable expression would be something like:

$V{myvariable} + 
($F{credit_or_debit}.equals("credit") ? new Integer(1) : new Integer(0))

和初始值value表达式将是 new Integer(0)

and the initial value expression would be new Integer(0)

然后在组页脚中你可以使用'print when expression '在静态文本上查看变量。

Then in the group footer you could use the 'print when expression' on the static text to look at the variable.

这篇关于在JasperReports中显示静态文本而不是空组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆