ntstha
ntstha

Reputation: 1173

Jasper Report merging cells in jasper table results in unwanted coulmn

i am fairly new to jasper report. I need to merge cells in jasper table and i have managed some portion of it. See following image.

enter image description here

as u can see that the there is empty cells. I need a single cells instead of multiple empty cells. Can you guys help me with me. I am stuck. I am posting my jrxml

<?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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9c6d12ac-438a-4209-b92b-fe8357e9a0ab">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="2"/>
    <style name="table">
        <box>
            <pen lineWidth="1.0" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TH" mode="Opaque" backcolor="#F0F8FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_CH" mode="Opaque" backcolor="#BFE1FF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <style name="table_TD" mode="Opaque" backcolor="#FFFFFF">
        <box>
            <pen lineWidth="0.5" lineColor="#000000"/>
        </box>
    </style>
    <subDataset name="medication" uuid="540773d1-98fb-48a3-9b89-a187c3e37e8a">
        <queryString language="SQL">
            <![CDATA[SELECT m.ID,m.medication_name,d.dose_time FROM medication m
LEFT JOIN dose_time d ON m.ID = d.medication_id;]]>
        </queryString>
        <field name="ID" class="java.lang.Integer">
            <fieldDescription><![CDATA[]]></fieldDescription>
        </field>
        <field name="medication_name" class="java.lang.String">
            <fieldDescription><![CDATA[]]></fieldDescription>
        </field>
        <field name="dose_time" class="java.lang.String">
            <fieldDescription><![CDATA[]]></fieldDescription>
        </field>
        <group name="ID">
            <groupExpression><![CDATA[$F{ID}]]></groupExpression>
        </group>
    </subDataset>
    <queryString>
        <![CDATA[select mdt.ID,mdt.medication_name,dt.dose_time from medication mdt left join dose_time dt on mdt.ID = dt.medication_id;]]>
    </queryString>
    <field name="ID" class="java.lang.Integer">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="medication_name" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="dose_time" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <background>
        <band splitType="Stretch"/>
    </background>
    <columnHeader>
        <band height="61" splitType="Stretch"/>
    </columnHeader>
    <detail>
        <band height="125" splitType="Stretch">
            <componentElement>
                <reportElement uuid="b80b6480-79a3-4c7a-b7e6-73e8df552d6a" key="table" style="table" x="0" y="0" width="555" height="125">
                    <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">
                    <datasetRun subDataset="medication" uuid="966ad176-a042-4a9f-b4fe-3c5cf2c43370">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="90" uuid="1674ad29-29a8-47d3-9bf9-fb233d836dcc">
                        <jr:groupFooter groupName="ID">
                            <jr:cell height="0" rowSpan="1"/>
                        </jr:groupFooter>
                        <jr:columnHeader style="table_CH" height="32" rowSpan="1">
                            <staticText>
                                <reportElement uuid="1e2c5349-4cc9-4caf-9d7f-ac34dfbdb1b4" x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <text><![CDATA[Medication Name]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="30" rowSpan="1">
                            <textField>
                                <reportElement uuid="cfeb2bce-6f8d-413c-8f4e-cfbe61cc2d24" style="table_TD" x="0" y="0" width="90" height="30">
                                    <printWhenExpression><![CDATA[$V{ID_COUNT}==1]]></printWhenExpression>
                                </reportElement>
                                <box leftPadding="0">
                                    <pen lineWidth="0.5"/>
                                    <topPen lineWidth="0.5"/>
                                    <leftPen lineWidth="0.5"/>
                                    <bottomPen lineWidth="0.5"/>
                                    <rightPen lineWidth="0.5"/>
                                </box>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{ID}+$F{medication_name}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="90" uuid="193e3bc0-bdba-42ec-824a-cb0e7b37b7d1">
                        <jr:columnHeader style="table_CH" height="32" rowSpan="1">
                            <staticText>
                                <reportElement uuid="c165e681-8db2-49af-9046-e3db70bfe0cf" x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <text><![CDATA[Doses Time]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="table_TD" height="30" rowSpan="1">
                            <textField>
                                <reportElement uuid="78fff516-49ab-4e1d-aa06-4c97d48bad0d" x="0" y="0" width="90" height="30"/>
                                <textElement/>
                                <textFieldExpression><![CDATA[$F{dose_time}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>

Upvotes: 0

Views: 4880

Answers (1)

marram
marram

Reputation: 439

I see two possible solutions here:

  1. Create a group band and group by "Medication Name" you will have empty cells but it will look cool :)
  2. Use some SQL kung-fu with the function concat_ws() to get the "Doses Time" in the same field as a list.

Have fun and I hope it helps.

Upvotes: 1

Related Questions