• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

How to hide column header if partucular column does not contains any value using ireport

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

How to hide Column Header if particular column does not contains any value

Hi,

I would like to hide the column header when there is no data available in a particular column fields .How do I implement this?

can we do this using fields name Properties object ie(windows----------------->properties) OR we Have to change int the XML CODE

Suppose i create one Table(Employee)which is having 4 fields

EmpId EmpFirstName EmpLastName EmpAge

1 William 22

2 Hengry Kerly 24

3 Robert Berly 34


output: if i select

select * from Employee where EmpId=1;

then my ireport will be generated like this

which column not having any details its not display in the report




EmpId EmpFirstName EmpAge

1 William 22


am news with ireport tools i dont know where we have to go change in the code

my Xml code is here

<?xml version="1.0" encoding="UTF-8"?>
<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="sample" language="groovy" pageWidth="842" pageHeight="595" orientation="Landscape" whenNoDataType="AllSectionsNoDetail" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="0" uuid="e6f67a14-570a-4046-9ab3-52cbb2cb9d36">
<property name="ireport.zoom" value="2.0"/>
<property name="ireport.x" value="450"/>
<property name="ireport.y" value="528"/>
<style name="Title" fontName="Serif" fontSize="26" isBold="true" pdfFontName="Helvetica-Bold"/>
<style name="SubTitle" forecolor="#666666" fontName="Serif" fontSize="18"/>
<style name="Column header" forecolor="#FFFFFF" fontName="Serif" fontSize="12" isBold="true"/>
<style name="Detail" fontName="Serif" fontSize="12"/>
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["/home/biztime/"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[SELECT * FROM Employee;]]>
</queryString>


<field name="EmployeeId" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="EmployeeFirstName" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="EmployeeSecondName" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="EmployeeAge" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<field name="EmployeeAddress" class="java.lang.String">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>



<variable name="EmployeeSecondName_1" class="java.lang.String" calculation="Count">
<variableExpression><![CDATA[$F{EmployeeSecondName}]]></variableExpression>
</variable>
<variable name="EmployeeId_1" class="java.lang.Integer" calculation="Count">
<variableExpression><![CDATA[$F{EmployeeId}]]></variableExpression>
</variable>
<variable name="EmployeeId_2" class="java.lang.Integer" resetType="Column" calculation="Count">
<variableExpression><![CDATA[$F{EmployeeId}]]></variableExpression>
</variable>
<variable name="EmployeeId_3" class="java.lang.Integer" calculation="Count">
<variableExpression><![CDATA[$F{EmployeeId}]]></variableExpression>
</variable>
<variable name="EmployeeId_4" class="java.lang.Integer" calculation="System">
<variableExpression><![CDATA[$F{EmployeeId}]]></variableExpression>
</variable>
<variable name="EmployeeId_5" class="java.lang.Integer" resetType="Column" calculation="Count">
<variableExpression><![CDATA[$F{EmployeeId}]]></variableExpression>
</variable>
<variable name="EmployeeFirstName_1" class="java.lang.String" resetType="Column" calculation="Count">
<variableExpression><![CDATA[$F{EmployeeFirstName}]]></variableExpression>
</variable>
<variable name="EmployeeAddress" class="java.lang.String" calculation="Count"/>





<group name="Group1">
<groupExpression><![CDATA[(int)($V{REPORT_COUNT}/15)]]></groupExpression>
<groupHeader>
<band height="40">
<staticText>
<reportElement mode="Transparent" x="12" y="13" width="100" height="20" isRemoveLineWhenBlank="true" uuid="3aeea084-6d27-457c-bb0e-5d455609fcde"/>
<textElement>
<font fontName="Serif" size="12" isBold="true"/>
</textElement>
<text><![CDATA[EmployeeId]]></text>
</staticText>
<staticText>
<reportElement x="146" y="10" width="177" height="20" isRemoveLineWhenBlank="true" uuid="664c98ba-24b9-4c87-8e86-eac17066a4e3"/>
<textElement markup="none">
<font fontName="Serif" size="12" isBold="true" isUnderline="false"/>
</textElement>
<text><![CDATA[EmployeeFirstName]]></text>
</staticText>
<staticText>
<reportElement x="323" y="13" width="154" height="20" isRemoveLineWhenBlank="true" uuid="f461036a-e9a0-4c21-9d7d-2a307e83a6d5"/>
<textElement>
<font fontName="Serif" size="12" isBold="true"/>
</textElement>
<text><![CDATA[EmployeeSecondName]]></text>
</staticText>
<staticText>
<reportElement x="699" y="13" width="103" height="20" uuid="959acc83-336f-4941-98c6-6b860f628bd7"/>
<textElement>
<font fontName="Serif" size="12" isBold="true"/>
</textElement>
<text><![CDATA[EmployeeAge]]></text>
</staticText>
<staticText>
<reportElement isPrintRepeatedValues="false" x="526" y="13" width="125" height="20" uuid="eff6e799-5902-444e-b586-15feb8a84ad7"/>
<textElement>
<font isBold="true"/>
</textElement>
<text><![CDATA[EmployeeAddress]]></text>
</staticText>
</band>
</groupHeader>
<groupFooter>
<band height="30">
<frame>
<reportElement mode="Opaque" x="652" y="0" width="150" height="30" forecolor="#CCCCCC" backcolor="#CCCCCC" uuid="9bcd5cd2-f3ed-41fc-9d6c-4702a5eb2d0a"/>
</frame>
</band>
</groupFooter>
</group>





<group name="Group2">
<groupExpression><![CDATA[(int)($V{REPORT_COUNT}/5)]]></groupExpression>


<groupHeader>
<band height="30"/>
</groupHeader>
</group>


<background>
<band height="575" splitType="Stretch">
<frame>
<reportElement mode="Opaque" x="-20" y="475" width="105" height="100" backcolor="#666666" uuid="622f9467-c399-4189-9d30-50ff7d9c52a5"/>
<textField>
<reportElement style="Column header" x="0" y="0" width="104" height="73" forecolor="#000000" uuid="f2a4aeb9-ff2e-44a5-9db2-bb5b0590e03a"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="54" isBold="true" pdfFontName="Helvetica-Bold"/>
</textElement>
<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement style="Column header" x="0" y="77" width="104" height="20" forecolor="#000000" uuid="96f7b50c-6c9d-441c-b9ec-e60299eac1ba"/>
<box leftPadding="4" rightPadding="4"/>
<textElement textAlignment="Center">
<font size="16" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>
<line>
<reportElement mode="Transparent" x="42" y="73" width="20" height="1" backcolor="#FFFFFF" uuid="2117cc39-0ba0-44ad-be80-98daa5324bc6"/>
</line>
</frame>
</band>
</background>
<title>
<band height="105" splitType="Stretch">
<staticText>
<reportElement x="222" y="35" width="280" height="36" uuid="48f86f36-c575-421a-ba54-797ace4f0917"/>
<textElement textAlignment="Justified">
<font fontName="Serif" size="24"/>
</textElement>
<text><![CDATA[ EMPLOYEE REPORT]]></text>
</staticText>
</band>
</title>



<pageHeader>
<band splitType="Stretch"/>
</pageHeader>





<columnHeader>
<band height="156" splitType="Stretch"/>
</columnHeader>



<detail>
<band height="31" splitType="Stretch">
<textField pattern="#,##0.00" isBlankWhenNull="true">
<reportElement x="0" y="5" width="98" height="20" isRemoveLineWhenBlank="true" uuid="c623e57a-404e-4820-91f4-a7808b3d316d"/>
<textElement>
<font fontName="Serif" isItalic="false" isUnderline="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{EmployeeId}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="163" y="5" width="128" height="23" uuid="73bc515a-8af9-4ef0-aca5-35bb41a30892"/>
<textFieldExpression><![CDATA[$F{EmployeeFirstName}]]></textFieldExpression>
</textField>
<textField pattern="" isBlankWhenNull="true">
<reportElement x="323" y="5" width="154" height="23" isRemoveLineWhenBlank="true" uuid="94e1ec36-478a-4761-b49a-8502057c2a08"/>
<textFieldExpression><![CDATA[$F{EmployeeSecondName}]]></textFieldExpression>
</textField>
<textField isBlankWhenNull="true">
<reportElement x="699" y="5" width="103" height="23" isRemoveLineWhenBlank="true" uuid="2d6f40ac-098a-4c11-a3cd-e432b1f12bb5"/>
<textFieldExpression><![CDATA[$F{EmployeeAge}]]></textFieldExpression>
</textField>
<textField>
<reportElement isPrintRepeatedValues="false" x="526" y="11" width="125" height="20" uuid="a7252ea2-52b4-49ba-8a2a-88517600bdfa"/>
<textFieldExpression><![CDATA[$F{EmployeeAddress}]]></textFieldExpression>
</textField>
</band>
</detail>




<columnFooter>
<band splitType="Stretch"/>
</columnFooter>


<pageFooter>
<band height="39" splitType="Stretch">
<textField pattern="EEEEE dd MMMMM yyyy">
<reportElement style="Column header" x="671" y="0" width="131" height="20" forecolor="#000000" uuid="1632c120-8789-4389-8a3e-8e68b964393d"/>
<textElement textAlignment="Right">
<font size="12" isBold="false"/>
</textElement>
<textFieldExpression><![CDATA[new java.util.Date()]]></textFieldExpression>
</textField>
</band>
</pageFooter>


<summary>
<band splitType="Stretch"/>
</summary>
</jasperReport>










Thanks & Regards
 
Power corrupts. Absolute power xxxxxxxxxxxxxxxx is kinda neat.
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!