I want to make a table with dynamic headers for a PDF in Grails using Jasper. One of the possible solutions would be to have a property as a value for an xml attribute. I have a hard time explaining it in English,so maybe it's better to leave an example, here is the xml code for a static header in a table:
<staticText>
<reportElement x="29" y="183" width="118" height="32"/>
<box>
<pen lineWidth="1.0"/>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<text><![CDATA[Column header text]]></text>
</staticText>
What I want to know is, is it possible to have a parameter for the value of x, y and every other attribute value for the element, like for an example this:
<staticText>
<reportElement x="<![CDATA[$P{columnX}]]>" y="<![CDATA[$P{columnY}]]>" width="<![CDATA[$P{columnWidth}]]>" height=32/>
<box>
<pen lineWidth="1.0"/>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center">
<font isBold="true"/>
</textElement>
<text><![CDATA[Column header text]]></text>
</staticText>
The parameter would be declared like this:
<parameter name="columnX" class="java.lang.Long"/>
Related
<staticText>
<reportElement x="100" y="0" width="100" height="25" backcolor="#A6A6A6" />
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Center"/>
<text><![CDATA[Nom]]></text>
</staticText>
I need to change the background color, i tried the attribute " backcolor="#A6A6A6" " but it it doesn't work!
You also need to set mode="Opaque".
I use traditional Chinese ,and set the Stretch with overflow.
I find the Jasper report lose some characters like above picture when it would create a new line.
my jrxml text :
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToBandHeight" x="352" y="0" width="140" height="30" isPrintWhenDetailOverflows="true" uuid="9855b06a-dfca-4a88-8830-efb1590c2d4e"/>
<box topPadding="1" leftPadding="4" bottomPadding="5" rightPadding="4">
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement verticalAlignment="Middle">
<font fontName="標楷體" pdfFontName="MHei-Medium" pdfEncoding="UniCNS-UCS2-H" isPdfEmbedded="true"/>
<paragraph lineSpacing="Single" lineSpacingSize="1.1"/>
</textElement>
<textFieldExpression><![CDATA[$F{varyReason}]]></textFieldExpression>
</textField>
Do I lose some setting???
Some attribute character is coming in the next line.it should come in one line
Example:
Student looking like
Student
but name is looking like
nam
e
The code is
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="200" height="21" uuid="e3b2f0ba-d810-42d5-aad6-74b440e871c6"/>
<box>
<pen lineWidth="1.0"/>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0" lineStyle="Solid"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement>
<font fontName="SansSerif" size="8" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
</textField>
How i can remove the space between detail and last page footer in JasperReports?
I need to remove the white space between them
I use this code for lastpagefooter
<lastPageFooter>
<band height="187">
<staticText>
<reportElement x="125" y="0" width="68" height="20" uuid="d7bc9c8a-c20b-4f79-8515-639609ead0cc"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="14"/>
</textElement>
<text><![CDATA[المجموع : ]]></text>
</staticText>
<textField>
<reportElement x="35" y="0" width="90" height="20" uuid="4b93f507-3e79-4ba7-99ce-d65b64a1a78b"/>
<box>
<topPen lineWidth="1.0"/>
<leftPen lineWidth="1.0"/>
<bottomPen lineWidth="1.0"/>
<rightPen lineWidth="1.0"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="14"/>
</textElement>
<textFieldExpression><![CDATA[$P{Totals}]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="23" y="167" width="40" height="20" uuid="c0c0de0b-7bb5-4133-bf5e-dfe51f91dac4"/>
<box rightPadding="2"/>
<textElement textAlignment="Right"/>
</band>
</lastPageFooter>
http://www.gulfup.com/?lV8MpF
This is the file
I just change the propriety of report Ignore pagination to true
<jasperReport ... isIgnorePagination="true" ...>
The problem in this case that i can't use breakI want to break to a new page when the number of the rows
finally, I use group footer and i add the total in it
I am working with jasper report-4.5.0.I want to hide a field in jasper based on the flag value.Below is tha code which i am using in columnHeader band.
<staticText>
<reportElement x="365" y="0" width="100" height="20"/>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[TotalCharge]]></text>
</staticText>
and below code i am using in detail band.
<textField>
<reportElement x="365" y="0" width="100" height="20">
<printWhenExpression><![CDATA[!$P{dataType}]]></printWhenExpression>
</reportElement>
<box>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font size="8"/>
</textElement>
<textFieldExpression><![CDATA[$F{chargeTotal}]]></textFieldExpression>
</textField>
i am declaring the parameter in jrxml as
<parameter name="dataType" class="java.lang.Boolean"/>
the value to this parameter is coming from java class.If it is the false value i dont want to display this chargeTotal column.What i am doing wrong in my code.I am not getting.Any one can point me where i am doing wrong its urgent to me.
The code snippets you provided for the textfield look correct, but if you are wanting to hide the column header also you need to also add a printWhenExpression for it.
<staticText>
<reportElement x="365" y="0" width="100" height="20">
<printWhenExpression><![CDATA[$P{dataType}]]></printWhenExpression>
</reportElement>
<box>
<topPen lineWidth="0.25"/>
<leftPen lineWidth="0.25"/>
<bottomPen lineWidth="0.25"/>
<rightPen lineWidth="0.25"/>
</box>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="true"/>
</textElement>
<text><![CDATA[TotalCharge]]></text>
</staticText>
Edit: Actually, you have the conditional value backwards. If you want to show the column when dataType is true, your printWhenExpression needs to look like:
<printWhenExpression><![CDATA[$P{dataType}]]></printWhenExpression>