How to set table column footer to the bottom of the detail band? - jasper-reports

I'm using table in jasperreport and I need to add table column footer to the bottom just before "group footer" band like
But currently it generates table like here
as you can see a lot of spaces between the table (which in detail band) and group footer band..
<detail>
<band height="80">
<componentElement>
<reportElement key="table1" style="tableStyle" x="1" y="0" width="552" height="80" isPrintWhenDetailOverflows="true" uuid="9a24d27b-9228-4f23-8c02-628268479882">
<printWhenExpression><![CDATA[$V{REPORT_COUNT} == 1]]></printWhenExpression>
</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" whenNoDataType="AllSectionsNoDetail">
<datasetRun subDataset="TableDataset" uuid="aad66998-86ba-485c-b8f4-3f2f6eda4796">
<dataSourceExpression><![CDATA[$P{datasourceItems}]]></dataSourceExpression>
</datasetRun>
<jr:column width="25" uuid="eb2f74b3-8006-4762-a52e-838f5e08a86f">
<jr:columnHeader height="40" rowSpan="2">
<staticText>
<reportElement style="tableProduct_CH" x="0" y="0" width="25" height="40" uuid="6ce8147d-c282-467a-b348-0d5cf3def735"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<text><![CDATA[No]]></text>
</staticText>
</jr:columnHeader>
<jr:columnFooter style="tableProductFooterNoLine" height="20" rowSpan="1"/>
<jr:detailCell height="20" rowSpan="1">
<textField isStretchWithOverflow="true">
<reportElement style="tableProduct_TD" x="0" y="0" width="25" height="20" uuid="fc581740-46a3-4602-b769-18beca53d355"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$F{no}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column> ...
</jr:table>
</componentElement>
</band>
</detail>

AFIK: This is not possible in jasper reports version <=6.7 (current version at date of answer) using the jr:table component.
You could draw the lines in the background band and then add the footer for example in a groupFooter band, but I would instead suggest that you create a subreport to avoid problems with page break.
The subreport will mimic the table using the standard detail and columnFooter band, again you will be adding the vertical lines in the background band.
How the columnFooter will behave is define by the attribute isFloatColumnFooter hence in your case false

Related

Title Band auto height

Depending on Parameters some text fields are not displayed in Title Band header in my report.
But Title band height is fixed. So either I have empty blank space in title band when text fields are not displayed. Or there is compilation error when I make band height smaller and those fields are displayed.
So how to make dynamic Title Band height?
<parameter name="param" class="java.lang.Boolean">
<defaultValueExpression><![CDATA[true]]></defaultValueExpression>
</parameter>
<title>
<band height="128" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<staticText>
<reportElement x="30" y="90" width="100" height="30" uuid="4e7618ed-21d8-47d2-99fb-7b88a5b7cfce">
<printWhenExpression><![CDATA[$P{param}]]></printWhenExpression>
</reportElement>
<text><![CDATA[Static Text]]></text>
</staticText>
<textField>
<reportElement x="30" y="10" width="100" height="30" uuid="005a53c9-a02d-436f-b35d-526ccf4aace9"/>
<textFieldExpression><![CDATA["Text Field"]]></textFieldExpression>
</textField>
<textField>
<reportElement x="30" y="50" width="100" height="30" uuid="caa2031a-3b71-43a2-bb39-916599872e94"/>
<textFieldExpression><![CDATA["Text Field"]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="43" splitType="Stretch">
<textField>
<reportElement x="30" y="6" width="100" height="30" uuid="30652d38-43f3-4574-a743-bb6240c2cb52"/>
<textFieldExpression><![CDATA["Text Field"]]></textFieldExpression>
</textField>
</band>
</pageHeader>
In this example there is blank space when param == false.
But if I make title band height smaller there is compilation error.
You have to set isRemoveLineWhenBlank to true for the text field.
<reportElement x="30" y="90" width="100" height="30" isRemoveLineWhenBlank="true" uuid="4e7618ed-21d8-47d2-99fb-7b88a5b7cfce">

Table shift to left when one column hide in jasper table?

I am using jasper report and trying to make RTL report. My problem is that when I am hiding my column in table using printWhenExpression based on some condition my table shift to left. I am using below code to hide column in table.
<jr:column width="160" uuid="f9b26e92-337e-4fb9-a091-4a81469c6c49">
<printWhenExpression><![CDATA[System.getProperty("vehicle.event.uid.enabled").equals("true")]]></printWhenExpression>
<jr:columnHeader style="ColumnHeader" height="30" rowSpan="1">
<textField>
<reportElement style="ColumnHeader" x="0" y="0" width="160" height="30" uuid="b4043ada-2580-4602-9262-3791ce3c0807"/>
<textElement>
<font size="8" isBold="true" isItalic="false"/>
</textElement>
<textFieldExpression><![CDATA[$R{target.external.id}]]></textFieldExpression>
</textField>
</jr:columnHeader>
<jr:detailCell style="table_TD" height="20" rowSpan="1">
<textField isBlankWhenNull="true">
<reportElement style="TableTextContent" x="0" y="0" width="160" height="20" isPrintWhenDetailOverflows="true" uuid="9dc36daa-d5e5-417c-831d-ff1b92ef1b79"/>
<textElement>
<font size="8" isBold="false" isItalic="false"/>
</textElement>
<textFieldExpression><![CDATA[$F{personExternalId}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
is there is any way so that my table should not shift to left when one of its column which is on left in that table is dynamically hide?
If you want to keep the column and does not want text, remove print when condition on column and add it to text expression :
<textFieldExpression><![CDATA[System.getProperty("vehicle.event.uid.enabled").equals("true")?$R{target.external.id} : ""]]></textFieldExpression>

Jasper Reports - check if table is empty (no records) and hide table label

My scenario: 2 tables on Summary field, each table has its own dataset. Also, each table is labelled so there is a label just on top each table.All is ok, however if there is no data in table, table is not printed but table label is still visible.
I need to hide table label if table has no data. Is it even possible? I can't find any solution how to determine if table is empty or not, to set is as expression that will hide label.
Any ideas?
There is no problem to get the record count from your table component this is done by returning value
<returnValue fromVariable="REPORT_COUNT" toVariable="TABLE_COUNT"/>
However this will not solve you problem since you can not set the evalutationTime of the printWhenExpression, you can only set evalutationTime of the textFieldExpression
The problem is normally solved by moving your "table label" where it is expected to be, in the table header
From IDE group your columns and add the textField in the groupHeader inside the table header.
Example (jrxml result)
<componentElement>
<reportElement key="table" style="table" x="0" y="33" width="360" height="50" uuid="6a7d5ab9-f15d-4676-85b2-1e48f016c155"/>
<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="tableData" uuid="fa5df3de-f4c5-4bfc-8274-bd064e8b81e6">
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
</datasetRun>
<jr:columnGroup width="217" uuid="c96f6ab0-8cce-4dc7-b686-da6928e7cabb">
<jr:tableHeader height="61" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="217" height="61" uuid="98aa260d-7e84-4df7-89cc-fc1eabdcf656"/>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA["MY TABLE LABEL"]]></textFieldExpression>
</textField>
</jr:tableHeader>
<jr:column width="90" uuid="889a828a-ad48-40a0-81f4-326a95d6585c">
<jr:columnHeader style="table_CH" height="60" rowSpan="1"/>
<jr:detailCell style="table_TD" height="43" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="90" height="43" uuid="82b2a835-4373-4638-b75a-d43f531678ba"/>
<textFieldExpression><![CDATA[$F{myField1}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
<jr:column width="127" uuid="004c3afe-c39f-44e2-a82d-5c96697ebd7e">
<jr:columnHeader style="table_CH" height="60" rowSpan="1"/>
<jr:detailCell style="table_TD" height="43" rowSpan="1">
<textField>
<reportElement x="0" y="0" width="90" height="43" uuid="90287319-765f-49a0-9f80-0851f40f2b13"/>
<textFieldExpression><![CDATA[$F{myField2}]]></textFieldExpression>
</textField>
</jr:detailCell>
</jr:column>
</jr:columnGroup>
</jr:table>
</componentElement>

Auto height rectangle in detail band

I am using iReport. I want to know how to make an auto height rectangle?
as per this sample image of detail band. There is two part one is data part on right side which fetch data and show. and left side part is a textarea data which is passed as parameter.
I want to make both rectangle same height. It may possible that left side data height is bigger than right side part and vice versa. So I want to make both rectangle height same all the time.
For achieving this i use following code. where I don't use rectangles but a lines only
<columnHeader>
<line>
<reportElement x="0" y="28" width="555" height="1" uuid="9d2cb019-77f2-47a0-94f7-aa944b5c277e"/>
</line>
</band>
</columnHeader>
<detail>
<band height="13" splitType="Stretch">
<textField>
<reportElement x="472" y="0" width="50" height="13" uuid="4b51d986-b6f9-45e2-a151-e9d7f86007f3"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="DejaVu Sans" size="8" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{packing}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="526" y="0" width="27" height="13" uuid="930cf91c-710a-40c4-a899-fde5ddfd7ce4"/>
<textElement verticalAlignment="Middle">
<font fontName="DejaVu Sans" size="8" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{sli_pack}]]></textFieldExpression>
</textField>
<line>
<reportElement x="471" y="0" width="1" height="13" uuid="434d1954-3286-4539-a3d9-915f28364210"/>
</line>
<line>
<reportElement x="555" y="-1" width="1" height="13" uuid="39dab81d-1bb3-41bd-8fff-9780b7f65672"/>
</line>
<line>
<reportElement x="0" y="-1" width="1" height="13" uuid="8936db56-872f-434d-a39b-298ffdb99e57"/>
</line>
</band>
</detail>
<summary>
<band height="1" splitType="Stretch">
<line>
<reportElement x="0" y="-1" width="555" height="1" uuid="ba7dbcc7-fd20-4ee9-b593-480737f9b88c"/>
</line>
</band>
</summary>
But the issue with this way is corners of rectangle is not properly printed.
My questions are:
1) Is there any better way to do this?
2) how to draw a border of complete detail band?
3) How to do this with rectangle ?
Here is another try with rectangle around detail band but rectangle is repeated to each row.
<detail>
<band height="13" splitType="Stretch">
<rectangle>
<reportElement stretchType="RelativeToTallestObject" x="1" y="0" width="552" height="13" uuid="80b946be-ac5f-495d-a507-fec3e22ea751"/>
</rectangle>
<textField>
<reportElement x="465" y="0" width="50" height="13" uuid="4b51d986-b6f9-45e2-a151-e9d7f86007f3"/>
<textElement textAlignment="Right" verticalAlignment="Middle">
<font fontName="DejaVu Sans" size="8" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{packing}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="526" y="0" width="27" height="13" uuid="930cf91c-710a-40c4-a899-fde5ddfd7ce4"/>
<textElement verticalAlignment="Middle">
<font fontName="DejaVu Sans" size="8" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
</textElement>
<textFieldExpression><![CDATA[$F{sli_pack}]]></textFieldExpression>
</textField>
</band>
</detail>
Hello I think you can find the answer in their documentation in this Link:
https://community.jaspersoft.com/wiki/dynamically-set-table-row-height-data
To sum up here are the options you should enable.
I think you should have one rectangle and place a line in between. Use the property of line, check stretchWithOverflow to true. Simillarly with rectangle.
First select your field and set following properties (third one is most important):
Position type: float
Stretch type: relative to tallest object
Stretch with overflow: true (checked)

stretch a row to fit the data in jasper reports using iReport

How do i stretch a text field to fit the data, If data exceeds the band height the text field doesn't stretch. I have added the text field tag in my jrxml...
The example:
<textField isStretchWithOverflow="true" pattern="" isBlankWhenNull="true" evaluationTime="Now" hyperlinkType="None" hyperlinkTarget="Self" >
<reportElement
style="dNew"
mode="Opaque"
x="200"
y="0"
width="200"
height="19"
key="value-2"
stretchType="RelativeToTallestObject"
positionType="Float"
isPrintInFirstWholeBand="true"
isPrintWhenDetailOverflows="true"/>
<box></box>
<textElement textAlignment="Center" verticalAlignment="Top">
<font fontName="Arial" pdfFontName="Helvetica"/>
</textElement>
<textFieldExpression class="java.lang.String"><![CDATA[$F{DATA2}]]></textFieldExpression>
</textField>
Some bands do not stretch, but if you are talking about the detail band you can do something like this:
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="base" positionType="Float"
isPrintRepeatedValues="false" x="0" y="3"
width="380" height="26" isRemoveLineWhenBlank="true"/>
<textElement/>
<textFieldExpression class="java.lang.String">
<![CDATA[$P{information}]]></textFieldExpression>
</textField>
That is pasted from auto generated XML so there is a lot of extra stuff, but the isStretchWithOverflow="true" should work for you. This will make the field stretch down as the text fills it up.
I ususally use iReport to build my reports and it works quiet nicely. You can switch to an XML view in there too.