How to 'Remove Line When Blank' after evaluation?

0

Hi, 

I'm working with the latest jaspersoft studio version as of today.

I'm having a issue with the 'Remove Line When Blank' not working after it evaluates some data

Say in a report I have amounts in a column being added up with values (3,2,1,-3,-2,-1). Only after finding that they add up to 0 do I want to remove them all and leave no white space behind. How is this done?

here is an example .jrxml file to demonstrate

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0  -->
<!-- 2015-07-10T13:17:35 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" 
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
              xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" 
              name="Blank Template" 
              pageWidth="612" 
              pageHeight="792" 
              columnWidth="555" 
              leftMargin="0" 
              rightMargin="0" 
              topMargin="0" 
              bottomMargin="0" 
              uuid="22974b6e-10a0-4530-8d14-87b0b674ae2c"> 
    <property name="com.jaspersoft.studio.data.defaultdataadapter" 
              value="Sample DB"/>
    <queryString language="SQL">  
        <![CDATA[SELECT * FROM (values(1),(2),(3),(-3),(-2),(-1)) AS x]]> 
    </queryString> 
    <field name="C1" class="java.lang.Integer"/> 
    <variable name="Variable_1" class="java.lang.Integer" calculation="Sum">  
        <variableExpression>
            <![CDATA[$F{C1}]]>
        </variableExpression> 
    </variable> 
    <columnHeader>  
        <band height="13" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="100" height="13" 
                               uuid="f8b9997e-98e5-4123-8533-054558ef12e2">
                    <property name="com.jaspersoft.studio.unit.height" 
                              value="pixel"/>
                </reportElement>
                <text><![CDATA[col header]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="13" splitType="Stretch">
            <textField evaluationTime="Auto" isBlankWhenNull="true">
                <reportElement x="0" y="0" width="180" height="13" isRemoveLineWhenBlank="true"
                               uuid="b6b32530-7b05-4d24-837f-8eb7f396733d">
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                </reportElement>
                <textElement markup="none"/>
                <textFieldExpression>
                    <![CDATA[$V{Variable_1} != 0 ? $F{C1} : ""]]>
                </textFieldExpression>
            </textField>
        </band>
    </detail>
    <summary>
        <band height="13">
            <staticText>
                <reportElement x="0" y="0" width="100" height="13"
                               uuid="b5d6692a-d851-4669-9dc7-b832ca674365">
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                </reportElement>
                <text>
                    <![CDATA[summary]]>
                </text>
            </staticText>
        </band>
    </summary>
</jasperReport>

As you can see from the example, it generates white space in the report when I do not want it to.
I am aware that I can do a 'SUM' in the main SQL query as a subquery to know if its '0' or not before drawing to the report but with large scale reports there can be lots of efficiency lost by doing this.

Hoping someone can help..thanks

linden's picture
15
Joined: Apr 18 2014 - 7:30pm
Last seen: 1 month 1 week ago

Select the text field and go to properties in that go to Appearance tab in that u can see "Remove Line When Blank" check box check that check box.

Thanks
B Ram krishna

RamaKrishna.B - 4 years 5 months ago

1 Answer:

0

If you apply "Remove Line When Blank" for all your text fields + set "Evaluation Time" for them as "Now", you will have the expected result.

Sharing the final source code for this report (added there some values for showing the result):

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 7.1.0.final using JasperReports Library version 6.4.3  -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Blank Template" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="22974b6e-10a0-4530-8d14-87b0b674ae2c">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
    <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
    <queryString language="SQL">
        <![CDATA[SELECT * FROM (values(1),(2),(3),(-1),(-2),(-3),(4),(-4), (-5)) AS x]]>
    </queryString>
    <field name="C1" class="java.lang.Integer">
        <property name="com.jaspersoft.studio.field.label" value="C1"/>
    </field>
    <variable name="Variable_1" class="java.lang.Integer" calculation="Sum">
        <variableExpression><![CDATA[$F{C1}]]></variableExpression>
    </variable>
    <columnHeader>
        <band height="13" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="100" height="13" uuid="f8b9997e-98e5-4123-8533-054558ef12e2">
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                </reportElement>
                <text><![CDATA[col header]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="13" splitType="Stretch">
            <textField isBlankWhenNull="true">
                <reportElement x="0" y="0" width="180" height="13" isRemoveLineWhenBlank="true" uuid="b6b32530-7b05-4d24-837f-8eb7f396733d">
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                </reportElement>
                <textElement markup="none"/>
                <textFieldExpression><![CDATA[$V{Variable_1} != 0 ? $F{C1} : ""]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <summary>
        <band height="13">
            <staticText>
                <reportElement x="0" y="0" width="100" height="13" uuid="b5d6692a-d851-4669-9dc7-b832ca674365">
                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                </reportElement>
                <text><![CDATA[
                    summary
                ]]></text>
            </staticText>
        </band>
    </summary>
</jasperReport>
oleksandr.voloschuk's picture
Joined: Nov 24 2017 - 6:35am
Last seen: 8 months 5 days ago

thanks for reply but no, as you can see from the jrxml i already have that setting on

linden - 4 years 5 months ago
Feedback
randomness