如果datasource中的值为空,请删除文本字段? [英] Remove text field if value in datasource is empty?

查看:251
本文介绍了如果datasource中的值为空,请删除文本字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在iReports设计器中创建Jasper报告模板文件,是否可以防止在其数据源中的字段为空时显示静态文本字段?



<我知道我可以使用一定数量的JavaScript来处理报告中的数据。如果字段值为NULL或为空,是否可能隐藏元素?

解决方案


是如果字段值为NULL或
为空,可能隐藏元素?


是的,它是可能的。



1。对静态和文本字段使用打印表达式时属性



隐藏NULL或空字符串值的示例:

 < staticText> 
< reportElement x =52y =16width =100height =20>
< printWhenExpression><![CDATA [$ F {field1}!= null&& $ F {} FIELD1 .trim()长度()> 0]] GT;< / printWhenExpression>
< / reportElement>
< textElement />
< text><![CDATA [静态文字]]>< / text>
< / staticText>


< textField>
< reportElement x =170y =15width =100height =20>
< printWhenExpression><![CDATA [$ F {field2}!= null&& $ F {} FIELD2 .trim()长度()> 0]] GT;< / printWhenExpression>
< / reportElement>
< textElement />
< textFieldExpression><![CDATA [$ F {field2}]]>< / textFieldExpression>
< / textField>

2。对文本字段使用Blank Null属性



隐藏带有NULL值的文本字段的示例:

 < textField isBlankWhenNull =true> 
< reportElement x =340y =15width =100height =20/>
< textElement />
< textFieldExpression><![CDATA [$ F {field3}]]>< / textFieldExpression>
< / textField>

3。对空数据源使用无数据区域 - 无数据返回



如果数据源为空,则可以使用无数据带静态你需要的领域。要使用此频段,您必须将无数据时报告的属性设置为无数据部分。



示例:

 <?xml version =1.0encoding =UTF-8?> 
< jasperReport .. whenNoDataType =NoDataSection..>

...
< noData>
< band height =50>
< staticText>
< reportElement x =236y =18width =100height =20/>
< textElement />
< text><![CDATA [无数据]]>< / text>
< / staticText>
< / band>
< / noData>
< / jasperReport>


If I am creating a Jasper report template file in the iReports designer, is it possible to prevent a static text field from displaying if a field in its datasource is empty?

I know that I can use a certain amount of JavaScript to manipulate data in the report. Is it possible to perhaps hide an element if a field value is NULL or empty?

解决方案

Is it possible to perhaps hide an element if a field value is NULL or empty?

Yes, it is possible.

1. Using "Print When Expression" property for static and text fields

Sample for hiding NULL or "empty" string value:

        <staticText>
            <reportElement x="52" y="16" width="100" height="20">
                <printWhenExpression><![CDATA[$F{field1} != null && $F{field1}.trim().length()>0]]></printWhenExpression>
            </reportElement>
            <textElement/>
            <text><![CDATA[Static text]]></text>
        </staticText>


        <textField>
            <reportElement x="170" y="15" width="100" height="20">
                <printWhenExpression><![CDATA[$F{field2} != null && $F{field2}.trim().length()>0]]></printWhenExpression>
            </reportElement>
            <textElement/>
            <textFieldExpression><![CDATA[$F{field2}]]></textFieldExpression>
        </textField>

2. Using "Blank When Null" property for text fields

Sample for hiding text field with NULL value:

        <textField isBlankWhenNull="true">
            <reportElement x="340" y="15" width="100" height="20"/>
            <textElement/>
            <textFieldExpression><![CDATA[$F{field3}]]></textFieldExpression>
        </textField>

3. Using "No Data" band for empty datasource - no data returns

If datasource is empty you can use "No Data" band with static fields you needs. For using this band you must set "When No Data" report's property to "No Data Section".

Sample:

<?xml version="1.0" encoding="UTF-8"?>
<jasperReport .. whenNoDataType="NoDataSection" ..>

    ...
    <noData>
        <band height="50">
            <staticText>
                <reportElement x="236" y="18" width="100" height="20"/>
                <textElement/>
                <text><![CDATA[No data]]></text>
            </staticText>
        </band>
    </noData>
</jasperReport>

这篇关于如果datasource中的值为空,请删除文本字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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