Ireports, generate variable number of subreports

Asked

Viewed 36 times

0

I’m using Jasper for reporting, using Ireport to build Layouts. I have a main report that has a sub report (the reason for my problem), my main report receives a list of objects, I need to generate a sub-report for each item in this list and popular this sub-report with the respective item in the list. Someone knows how to do it, it’s possible to do it?

1 answer

1


You can put a table in your main report.

Something like:

<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="ItemDataset" uuid="d3e1e03a-2c83-4436-9e50-79518bc3d337">
                    <dataSourceExpression><![CDATA[$P{ItemDataSource}]]></dataSourceExpression>
                </datasetRun>
                <jr:column width="130" uuid="dca8961f-ce2d-47ac-879c-b15847d170a9">
                    <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                    <printWhenExpression><![CDATA[new Boolean(($V{REPORT_COUNT}.intValue()%2==0))]]></printWhenExpression>
                    <jr:tableHeader height="31" rowSpan="1">
                        <staticText>
                            <reportElement mode="Opaque" x="0" y="0" width="130" height="31" forecolor="#FFFFFF" backcolor="#3C8DCB" uuid="f60d1675-6fb6-4569-93ca-de32b3a8e861"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font fontName="Serif" isBold="true"/>
                            </textElement>
                            <text><![CDATA[Descrição]]></text>
                        </staticText>
                    </jr:tableHeader>
                    <jr:detailCell height="30" rowSpan="1">
                        <textField>
                            <reportElement mode="Opaque" x="0" y="0" width="130" height="30" backcolor="#FFFFFF" uuid="f1de366a-b36f-4200-9b1e-7a0009be5373"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle"/>
                            <textFieldExpression><![CDATA[$F{nome}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="140" uuid="980fffb5-1088-47a6-b00f-b5d08b7093c9">
                    <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                    <jr:tableHeader height="31" rowSpan="1">
                        <staticText>
                            <reportElement mode="Opaque" x="0" y="0" width="140" height="31" forecolor="#FFFFFF" backcolor="#3C8DCB" uuid="16679b95-2e6e-4ca1-b8b6-dd7b74267c56"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle">
                                <font fontName="Serif" isBold="true"/>
                            </textElement>
                            <text><![CDATA[Valor]]></text>
                        </staticText>
                    </jr:tableHeader>
                    <jr:detailCell height="30" rowSpan="1">
                        <textField>
                            <reportElement mode="Opaque" x="0" y="0" width="140" height="30" backcolor="#FFFFFF" uuid="341e7faf-9680-4941-a9a4-ac78b8f4aae0"/>
                            <textElement textAlignment="Center" verticalAlignment="Middle"/>
                            <textFieldExpression><![CDATA[$F{valor}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
            </jr:table>

and in Java you send the data from the list that you want to be a result table.

  • I’ll try this way.

  • 1

    It worked, thank you. A strong hug.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.