Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasper table component

I am trying to generate a report containing a table. These are the important parts from the jrxml:

<jasperReport
    <subDataset name="Table Dataset 1">
        <field name="field1" class="java.lang.String"/>
    </subDataset>
    <summary>
        <jr:table>
           <datasetRun subDataset="Table Dataset 1">
           <dataSourceExpression>
                        <![CDATA[$P{REPORT_DATA_SOURCE}]]>
                </dataSourceExpression>   
           </datasetRun>
           <jr:column width="90">
              <jr:columnHeader>...</jr:columnHeader>
              <jr:detailCell height="20">
              <textField>
                 <textFieldExpression class="java.lang.String">
                            <![CDATA[$F{territory}]]>
                         </textFieldExpression>
              </textField>
           </jr:detailCell>
           </jr:column>
        <jr:table>
    </summary>
</jasperReport>

The type of datasource I am passing to the report is a JRBeanArrayDataSource, which seems to be ok, because the data appears in the report (if I am using $F{field1} in the master - outside the table).

Do you see something wrong in the way I am using the table component? I don't see any errors...but the table is not being displayed...only a horizontal line instead of the table.

like image 390
teo Avatar asked Dec 30 '10 14:12

teo


People also ask

How do you use tables in Jasper report?

To create a table in a report, drag the Table element from the Elements palette inside any band of the report. The Table Wizard opens with a choice of creating a table from a new or existing dataset. If you choose to create an empty table, a new dataset is created and bound to the table.

How does Jasper report connect to database?

Launch Jaspersoft Studio, if you have not done so already. Click the Repository Explorer button on the main toolbar to open the Connections/Datasources dialog box. Right-click on Data Adapters and select Create Data Adapter. Select Database JDBC Connection and click Next to advance to the Database JDBC connection page.

How do I add dynamic columns in Jasper report?

In Jasper Report, you can use 'printWhenExpression' where you can print a particular row/column/value based on a certain condition. If you know the max no. of columns then add those columns in your design and then hide them using printWhenExpression.


1 Answers

I had the same problem and found the solution here https://web.archive.org/web/20111130110022/http://thilosdevblog.wordpress.com/2011/03/27/beans-in-jasperreports4/

the table datasource has to be like this:

<datasetRun subDataset="TableDataset">
    <datasetParameter name="REPORT_DATA_SOURCE">
       <datasetParameterExpression><![CDATA[$P{REPORT_DATA_SOURCE}]]></datasetParameterExpression>
    </datasetParameter>
</datasetRun>

Wonder why this kind how stuff is not in the jasper/ireport FAQ !

like image 62
Flo Avatar answered Sep 22 '22 01:09

Flo