Jump to content
We've recently updated our Privacy Statement, available here ×

How to achieve the effect of merging cells


1140371340

Recommended Posts

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

You can create a table element inside the detail band to achieve this kind of merging. 

the detail band text element should have position type as Fix relative to Top and Stretch type as Relative to band height.

The table element would be growing based on the data, but the text element would be locked down at the top and stretching towards the bottom.

Check the below jrxml.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1  -->
<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="tablealignment" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="f6dbae90-77f7-4f15-b929-2fb39c55987c">
    <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>
    <subDataset name="Dataset1" uuid="14e0e132-36f8-4f16-8e64-12d231b45acf">
        <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="PRODSUP"/>
        <parameter name="ID" class="java.math.BigDecimal"/>
        <queryString language="SQL">
            <![CDATA[select * from ( 
select 1 as ID, 'Color1-1' as text from dual union all
select 1 as ID, 'Color1-2' as text from dual union all
select 1 as ID, 'Color1-3' as text from dual union all
select 2 as ID, 'Color2-1' as text from dual union all
select 3 as ID, 'Color3-1' as text from dual union all
select 3 as ID, 'Color3-2' as text from dual union all
select 3 as ID, 'Color3-3' as text from dual union all
select 3 as ID, 'Color3-4' as text from dual union all
select 3 as ID, 'Color3-5' as text from dual ) 
where ID  =  $P{ID}]]>
        </queryString>
        <field name="ID" class="java.math.BigDecimal"/>
        <field name="TEXT" class="java.lang.String"/>
    </subDataset>
    <queryString language="SQL">
        <![CDATA[select 1 as ID, 'One' as text from dual union all
select 2 as ID, 'Two' as text from dual union all
select 3 as ID, 'Three' as text from dual]]>
    </queryString>
    <field name="TEXT" class="java.lang.String"/>
    <field name="ID" class="java.math.BigDecimal"/>
    <group name="ID">
        <groupExpression><![CDATA[$F{ID}]]></groupExpression>
    </group>
    <background>
        <band splitType="Stretch"/>
    </background>
    <columnHeader>
        <band height="20" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="0" width="80" height="20" uuid="ab262d73-28fe-4290-9bb3-fd12f0cf277b"/>
                <text><![CDATA[Column Header]]></text>
            </staticText>
            <staticText>
                <reportElement x="80" y="0" width="100" height="20" uuid="8e7b84f5-2e38-4c87-8714-7c178f72e83b"/>
                <text><![CDATA[Table Header]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="20" splitType="Stretch">
            <textField>
                <reportElement stretchType="RelativeToBandHeight" x="0" y="0" width="80" height="20" uuid="404e4662-e55c-4781-b306-22436e82f293"/>
                <box>
                    <pen lineWidth="1.0"/>
                </box>
                <textFieldExpression><![CDATA[$F{TEXT}]]></textFieldExpression>
            </textField>
            <componentElement>
                <reportElement x="80" y="0" width="100" height="20" uuid="0cdcdc65-ef96-4d7c-b660-5f53e2d1ec19">
                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                    <property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
                    <property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
                    <property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
                </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="544c6f50-1f07-4684-9297-7b22e2a19e30">
                        <datasetParameter name="ID">
                            <datasetParameterExpression><![CDATA[$F{ID}]]></datasetParameterExpression>
                        </datasetParameter>
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="100" uuid="bfcaa2cb-4b81-42d4-aea8-87c5cd753369">
                        <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                        <jr:detailCell style="Table_TD" height="20">
                            <property name="com.jaspersoft.studio.unit.height" value="px"/>
                            <property name="com.jaspersoft.studio.unit.width" value="px"/>
                            <box>
                                <pen lineWidth="1.0"/>
                            </box>
                            <textField>
                                <reportElement x="0" y="0" width="100" height="20" uuid="c343f8cf-faef-472a-864d-d20dc4f8998b"/>
                                <textFieldExpression><![CDATA[$F{TEXT}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </band>
    </detail>
</jasperReport>
 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...