PP Ocean Posted January 20, 2017 Share Posted January 20, 2017 Hi all,I am using Jasper Studio 6.1 version. I want to hide some columns in the report rather than deleting them. I have totally 10 columns in JRXML file which I want to hide 5 columns. Is there any way for this?Thanks Link to comment Share on other sites More sharing options...
sanbez Posted January 20, 2017 Share Posted January 20, 2017 You can use Table component and set printWhenExpression on column of table Link to comment Share on other sites More sharing options...
PP Ocean Posted January 20, 2017 Author Share Posted January 20, 2017 Hi,I am already using Table. Can you please tell me an example i.e what expression I need to write in "printWhenExpression"?Thanks. Link to comment Share on other sites More sharing options...
Solution reportdev Posted January 20, 2017 Solution Share Posted January 20, 2017 <?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 --><!-- 2017-01-20T11:28:34 --><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Blank_A4" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" whenResourceMissingType="Error" uuid="9f00c1c7-09ad-4cdb-a26c-48d2f2038207"> <property name="com.jaspersoft.studio.unit." value="pixel"/> <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/> <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <style name="Table_TH" mode="Opaque" backcolor="#F0F8FF"> <box> <pen lineWidth="0.5" lineColor="#000000"/> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> </style> <style name="Table_CH" mode="Opaque" backcolor="#BFE1FF"> <box> <pen lineWidth="0.5" lineColor="#000000"/> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> </style> <style name="Table_TD" mode="Opaque" backcolor="#FFFFFF"> <box> <pen lineWidth="0.5" lineColor="#000000"/> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> </style> <style name="Table 1_TH" mode="Opaque" backcolor="#F0F8FF"> <box> <pen lineWidth="0.5" lineColor="#000000"/> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> </style> <style name="Table 1_CH" mode="Opaque" backcolor="#BFE1FF"> <box> <pen lineWidth="0.5" lineColor="#000000"/> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> </style> <style name="Table 1_TD" mode="Opaque" backcolor="#FFFFFF"> <box> <pen lineWidth="0.5" lineColor="#000000"/> <topPen lineWidth="0.5" lineColor="#000000"/> <leftPen lineWidth="0.5" lineColor="#000000"/> <bottomPen lineWidth="0.5" lineColor="#000000"/> <rightPen lineWidth="0.5" lineColor="#000000"/> </box> </style> <subDataset name="Dataset1" uuid="276df825-0b12-4d93-ad31-8d4eb16741cd"> <property name="com.jaspersoft.studio.data.sql.tables" value=""/> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/> <parameter name="ORDERID" class="java.lang.Integer"/> <parameter name="CUSTOMERID" class="java.lang.String"/> <parameter name="EMPLOYEEID" class="java.lang.Integer"/> <queryString> <![CDATA[select * from orderswhere(ORDERID = $P{ORDERID} )or(CUSTOMERID = $P{CUSTOMERID} )or(EMPLOYEEID = $P{EMPLOYEEID} )]]> </queryString> <field name="ORDERID" class="java.lang.Integer"/> <field name="CUSTOMERID" class="java.lang.String"/> <field name="EMPLOYEEID" class="java.lang.Integer"/> <sortField name="ORDERID"/> <sortField name="CUSTOMERID"/> <sortField name="EMPLOYEEID"/> </subDataset> <parameter name="ORDERID" class="java.lang.Integer"/> <parameter name="CUSTOMERID" class="java.lang.String"> <parameterDescription><![CDATA[]]></parameterDescription> </parameter> <parameter name="EMPLOYEEID" class="java.lang.Integer"/> <queryString> <![CDATA[select * from orders]]> </queryString> <field name="ORDERID" class="java.lang.Integer"/> <field name="CUSTOMERID" class="java.lang.String"/> <field name="EMPLOYEEID" class="java.lang.Integer"/> <field name="ORDERDATE" class="java.sql.Timestamp"/> <field name="REQUIREDDATE" class="java.sql.Timestamp"/> <field name="SHIPPEDDATE" class="java.sql.Timestamp"/> <field name="SHIPVIA" class="java.lang.Integer"/> <field name="FREIGHT" class="java.math.BigDecimal"/> <field name="SHIPNAME" class="java.lang.String"/> <field name="SHIPADDRESS" class="java.lang.String"/> <field name="SHIPCITY" class="java.lang.String"/> <field name="SHIPREGION" class="java.lang.String"/> <field name="SHIPPOSTALCODE" class="java.lang.String"/> <field name="SHIPCOUNTRY" class="java.lang.String"/> <background> <band splitType="Stretch"/> </background> <summary> <band height="40"> <componentElement> <reportElement x="0" y="0" width="555" height="40" uuid="6a587605-24fc-463c-b0d2-951d1cf79c69"> <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/> </reportElement> <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd"> <datasetRun subDataset="Dataset1" uuid="7285622c-58e8-45af-8a62-f63d55444319"> <datasetParameter name="CUSTOMERID"> <datasetParameterExpression><![CDATA[$P{CUSTOMERID}]]></datasetParameterExpression> </datasetParameter> <datasetParameter name="EMPLOYEEID"> <datasetParameterExpression><![CDATA[$P{EMPLOYEEID}]]></datasetParameterExpression> </datasetParameter> <datasetParameter name="ORDERID"> <datasetParameterExpression><![CDATA[$P{ORDERID}]]></datasetParameterExpression> </datasetParameter> <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression> </datasetRun> <jr:column width="180" uuid="136cfb9c-9a82-433d-b657-c07594d897b7"> <property name="com.jaspersoft.studio.unit.width" value="pixel"/> <printWhenExpression><![CDATA[(!$P{ORDERID}.equals(null))== true]]></printWhenExpression> <jr:columnHeader style="Table 1_CH" height="20"> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <staticText> <reportElement x="0" y="0" width="180" height="20" uuid="65809bae-ceee-459d-99b5-81031dbd6695"/> <box leftPadding="5"/> <textElement verticalAlignment="Middle"> <font isBold="true" isUnderline="true"/> </textElement> <text><![CDATA[ORDERID]]></text> </staticText> </jr:columnHeader> <jr:detailCell style="Table 1_TD" height="20"> <property name="com.jaspersoft.studio.unit.height" value="px"/> <textField> <reportElement x="0" y="0" width="180" height="20" uuid="79b6944c-0460-4da3-88ba-11ebdfbaed90"/> <box leftPadding="5"/> <textElement verticalAlignment="Middle"/> <textFieldExpression><![CDATA[$F{ORDERID}]]></textFieldExpression> </textField> </jr:detailCell> </jr:column> <jr:column width="200" uuid="48fccd5c-4ba2-477e-86d2-581754ca8df0"> <property name="com.jaspersoft.studio.unit.width" value="pixel"/> <printWhenExpression><![CDATA[(!$P{CUSTOMERID}.equals(null))== true]]></printWhenExpression> <jr:columnHeader style="Table 1_CH" height="20"> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <staticText> <reportElement x="0" y="0" width="200" height="20" uuid="6ca7facf-140e-43e7-875d-c7138fcf488c"/> <box leftPadding="5"/> <textElement verticalAlignment="Middle"> <font isBold="true" isUnderline="true"/> </textElement> <text><![CDATA[CUSTOMERID]]></text> </staticText> </jr:columnHeader> <jr:detailCell style="Table 1_TD" height="20"> <property name="com.jaspersoft.studio.unit.height" value="px"/> <textField> <reportElement x="0" y="0" width="200" height="20" uuid="4df4059c-5430-44ba-beed-7c5878c6d426"/> <box leftPadding="5"/> <textElement verticalAlignment="Middle"/> <textFieldExpression><![CDATA[$F{CUSTOMERID}]]></textFieldExpression> </textField> </jr:detailCell> </jr:column> <jr:column width="170" uuid="07332bb7-ff68-430a-98ed-3a35025436cb"> <property name="com.jaspersoft.studio.unit.width" value="pixel"/> <printWhenExpression><![CDATA[(!$P{EMPLOYEEID}.equals(null))== true]]></printWhenExpression> <jr:columnHeader style="Table 1_CH" height="20"> <property name="com.jaspersoft.studio.unit.width" value="px"/> <property name="com.jaspersoft.studio.unit.height" value="px"/> <staticText> <reportElement x="0" y="0" width="170" height="20" uuid="72125348-ce1b-44e7-9977-dbcff95a978e"/> <box leftPadding="5"/> <textElement verticalAlignment="Middle"> <font isBold="true" isUnderline="true"/> </textElement> <text><![CDATA[EMPLOYEEID]]></text> </staticText> </jr:columnHeader> <jr:detailCell style="Table 1_TD" height="20"> <property name="com.jaspersoft.studio.unit.height" value="px"/> <textField> <reportElement x="0" y="0" width="170" height="20" uuid="c49e8e00-ba67-4df2-8808-e0290460d643"/> <box leftPadding="5"/> <textElement verticalAlignment="Middle"/> <textFieldExpression><![CDATA[$F{EMPLOYEEID}]]></textFieldExpression> </textField> </jr:detailCell> </jr:column> </jr:table> </componentElement> </band> </summary></jasperReport>[/code]I have written this jrxml for the same purpose.when you enter some value into the parameter for the respective column, it disappears.Check the print when expression on the Columns Link to comment Share on other sites More sharing options...
sanbez Posted January 23, 2017 Share Posted January 23, 2017 Good example to show columnPrintWhenExpressionbut!$P{EMPLOYEEID}.equals(null) - it is nonsense (imho)It always true when $P{EMPLOYEEID} != nullIt cause NPE when $P{EMPLOYEEID} == nullTo topicstarter:Discussion without your code (description of condition on column) is not efficient.Show jrxml and describe condition which you want Link to comment Share on other sites More sharing options...
PP Ocean Posted January 25, 2017 Author Share Posted January 25, 2017 Thanks reportdev. Your solution is working. I have used field instead of parameter. 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