Search code examples
jasper-reports

Hide full table based on empty fields


I want to hide the full table when certain columns are empty:

The following table should be hidden because Param2, Param3 and Param4 columns are empty

Param1 Param2 Param3 Param4

A

B

C

If any of the Param2, Param3 and Param4 is not empty than the table should be shown.

Param1 Param2 Param3 Param4

A

B______________1

C

Does anyone has an idea on how to do that?


Solution

    1. The JasperReport Table component has a property <printWhenExpression>. This takes a boolean value and shows the component if it is set to true (and it will not be displayed otherwise. So the only thing you should do would be iterating through each column (except the first), check if there is a value or not (by checking isEmpty) and the boolean retrieved would be used inside printWhenExpression. Or even better, check if the dataset/query returns any record at all.

    2. Another easier way might be is putting your table into a subreport, on it's properties set When No Data as No Data Section or Blank Page, and include the subreport into your main report.