I have a table in iReport with 3 fields (A, B, C). I would to print the row iff field C is not null. For example if I have 2 records in my data source:
A = first, B = second, C = third
A = up, B = down, C = NULL
the table must have only the first row.
I have tried inserting this expression in each cell (in "Print when expression" property):
!$F{C}.equals(null)
but in this way the result is that the second row is empty (but visible).
Edit: after the first answer (now erased) the columns in the table are something like:
<jr:column ...>
<jr:columnHeader ...>
<staticText>
<reportElement .../>
<text><![CDATA[ID]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell ...>
<textField isBlankWhenNull="false">
<reportElement ... isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[$F{ID}!=null]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$F{ID}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column ...>
<jr:columnHeader ...>
<staticText>
<reportElement .../>
<text><![CDATA[CITY]]></text>
</staticText>
</jr:columnHeader>
<jr:detailCell ...>
<textField isBlankWhenNull="false">
<reportElement ... isRemoveLineWhenBlank="true">
<printWhenExpression><![CDATA[$F{ID}!=null]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$F{CITY}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
The data source is a xml file. I've tried also with isBlankWhenNull="true"
but with no change. Here a screen of the result:
When you put the print when expression on the field, only the field will be removed. Hence, the space will remain. Put the same expression on the detail band and try again.
Edit:
Looking at the problem further, I've noticed there is no option to omit records (Print When Expression) at the detail level of the table element. That option doesn't exist as you can see in iReport and also in the schema definition. Furthermore, the reason isBlankWhenNull="true"
isn't working is because, even though the textfield is empty, the detail row still takes up the allocated height. Also, the PrintWhenExpression you tried to modify applies to the whole table and not the row. So it doesn't seem like it is possible to do the way you were hoping.
Here I will give you these steps to solve your problem:
((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/root[c!='']")
Good Luck.