Subdataset - total rows in the List

2019-08-29 19:48发布

I have created a subdataset in my main report and using that to create a list. The list displays all the rows from my dataset, but is there a way to place a total number of rows count in the list component.

With the $V{REPORT_COUNT} variable, i can get the total count but its repeated multiple times (as the number of rows in the sub dataset )

2条回答
ら.Afraid
2楼-- · 2019-08-29 20:30

Create A second List set it to use the same dataset and put only the $V{REPORT_COUNT} in it. Set the position type to float

Second option is to use the Table in place of the List as it has the banding to allow for a header or footer of your dataset

查看更多
劫难
3楼-- · 2019-08-29 20:34

As noted in the answer by user jmurray here: http://community.jaspersoft.com/questions/514827/row-count

In your subDataSet, create a variable:

<variable name="ROW_COUNTER" class="java.lang.Integer" incrementType="Report" calculation="Count">
    <variableExpression><![CDATA[new java.lang.Integer(1)]]></variableExpression>
    <initialValueExpression><![CDATA[new java.lang.Integer(0)]]></initialValueExpression>
</variable>

Then somewhat like what Mike Noland has in his answer, create a list that points to the same subDataSet as the original list with a textField:

<textField>
    <reportElement isPrintRepeatedValues="false" x="0" y="0" width="100" height="11"/>
    <textFieldExpression><![CDATA[new java.lang.Integer($V{ROW_COUNTER}.intValue()+1)]]></textFieldExpression>
</textField>

This creates a zero based counter that holds the total count of items. Then by telling the report not to print repeats, you end up with a single item that represents the total number of items in your subDataSet

查看更多
登录 后发表回答