Dawood
Dawood

Reputation: 301

JasperReports: display a column or field if it is visible else do not display

I have a requirement in JasperReports wherein I need to display the field based on a user's configuration. If the field is visible to the user then display the field else the field will be hidden. Can anybody please suggest me the solution for this?

Upvotes: 0

Views: 5005

Answers (1)

Alex K
Alex K

Reputation: 22857

You can use the parameter for setting condition to hide the field or not.

The one way is to set parameter with help of JasperReports API.

The sample code for setting parameter and building report:

Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("isFieldHidden", true);

JasperFillManager.fillReportToFile(report, parameters, connection);

The snippet of the report template (jrxml file):

<parameter name="isFieldHidden" class="java.lang.Boolean"/>
...
<textField>
    <reportElement x="100" y="0" width="100" height="20">
        <printWhenExpression><![CDATA[!$P{isFieldHidden}]]></printWhenExpression>
    </reportElement>
    <textElement/>
    <textFieldExpression><![CDATA[$F{city}]]></textFieldExpression>
</textField>

Upvotes: 2

Related Questions