How to erase rows in a table if the expression is valid in iReport

I have a table in iReport with three fields (A, B, C). I would like to print the line iff, the C field 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 should have only the first row.

I tried to insert this expression into each cell (in the "Print on expression" property):

!$F{C}.equals(null) 

but in this way the result is that the second line is empty (but visible).

Edit: after the first answer (now erased), the columns in the table look something like this:

 <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 an xml file. I tried also with isBlankWhenNull="true" , but no change. Here is the result screen: tab

+6
source share
4 answers

When you put a stamp on an expression in a field, only the field is deleted. Consequently, space will remain. Put the same expression in the detail range and try again.

Edit:

Looking at the problem further, I noticed that there are no options to omit records (Print When Expression) at the level of detail of the table element. This option does not exist, as you can see in iReport, as well as in the schema definition . Also, the reason isBlankWhenNull="true" does not work, because although the text field is empty, the part line still occupies the selected height. In addition, the PrintWhenExpression that you tried to change applies to the whole table, not the row. So it doesn't look like you can do as you hoped.

Here I will give you the following steps to solve your problem:

  • Update the XPath query to the dataset launch property (right-click> edit the datasource table from the table constructor view) so that entries where C is null are omitted.
  • Select your optional dataset and select Use Data Source Expression from the Connect / Data Source expression menu.
  • Insert the following expression:

((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/root[c!='']")

Good luck.

+1
source

I found another solution to this problem: For the dataset used for the table, adding a filter expression, for example. $ F {dateRemoved} == null.

This way, empty lines will be deleted.

+1
source

Directly responding to the problem:

  1. After use β†’ Print with expression
  2. Go just 1 inch higher and check the option "Delete row when empty"

  3. 100% works

0
source

Please, use

 isRemoveLineWhenBlank="true" 

for reportElement

0
source

Source: https://habr.com/ru/post/916469/


All Articles