ummekulsum4321 Posted March 12, 2020 Share Posted March 12, 2020 how can we hide a subreport if no data is present on a conditionin my case i have 4 subreport and how to avoid the space which is formed if no data is present Link to comment Share on other sites More sharing options...
I am Leo Posted March 13, 2020 Share Posted March 13, 2020 You can use printWhenExpression to show/hide your subreport.<subreport> <reportElement x="26" y="14" width="190" height="17" uuid="285bfacd-4092-4d3a-ac1f-6d72074350ae"> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="com.jaspersoft.studio.element.name" value="mySubreport"/> <printWhenExpression><![CDATA[$P{checkoutPointItems} == null || $P{checkoutPointItems}.isEmpty()]]></printWhenExpression> </reportElement> <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{checkoutPointItems})]]></dataSourceExpression> <subreportExpression><![CDATA["templates/pdf/subreports/checkout-point-item.jasper"]]></subreportExpression></subreport>[/code] Link to comment Share on other sites More sharing options...
ummekulsum4321 Posted March 13, 2020 Author Share Posted March 13, 2020 i wanted to hide the report the the data is null but instead its hiding even if data is present Link to comment Share on other sites More sharing options...
jgust Posted March 17, 2020 Share Posted March 17, 2020 If you know ahead of time that you want to suppress a band or subreport then @IAmLeo is correct that you can pre-emptively suppress it using the print when expression, either on the band or the subreport depending on your layout.If you want to suppress the subreport only if there is no data then I think what you need to do is set the "When No Data Type" field to "No Data Section" and make that section really small.Another option (I haven't tried this yet) would be to pass back a record count from the subreport using the Edit Return Values and see if you can suppress based on the return value. Like I said I haven't tried that yet. The "No Data Section" in the subreport has always worked well for me. Link to comment Share on other sites More sharing options...
Recommended Posts
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