How is it different from hiding non-table rows
The basic principle of hiding a row in a Table component is the same as hiding a row, say, in a Detail band. However, since the Text fields in a Table are nested in cells, there are a couple of additional requirements that need to be met to hide a row successfully. The details are described below.
Configuration steps
In the example below we will hide a Table Group row header when the Country field is NULL. Since the Table data is grouped by Country, we do not want the report to display the header when Country value is set to NULL.
Set a Print When Expression on ALL the Text fields in the Table row. If any of the Text fieds do not have the conditional expression the row will not be hidded even when the condition is met for the other fields in the row:
Outside the Table component this would in most cases be enough. For Tables, we also have to make sure the following conditions are also met:
- The cell which needs to be hidden should be completely filled by the nested Text fields, both by width and height. This means that the height of all the Text fields should be exactly the same as the cell height. It also means that if any part of the cell does not have a nested Text field, you have to add an empty field there and set the conditional expression for it too.
- The second requirement is that the cell has no borders. So if, for example, you are applying a style for the Table cell which sets the borders to anything other than 0 pixels, you'll have to remove the style from the cell. Instead, the style can be applied on the Text field level.
This should be it. See an example report attached. It should run against any valid JDBC data source.
Other notes
If you are receiving an error like this:
Field not found: myFieldName --- net.sf.jasperreports.engine.design.JRDesignExpression@c90ba2f
it most likely means that you have specified the Print When Expression for a Table cell and not for a Text Field nested inside the cell. The problem here is that report fields and parameters are not visible on the cell level. The simple solution is, again, to add an empty Text field inside the cell, and set the conditional expression there.
Recommended Comments
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now