The subreport repeats itself in Detail band

前端 未结 1 1911
囚心锁ツ
囚心锁ツ 2021-01-01 07:14

I am new to JasperReports, basically I want to put a subreport in a mainreport

The problem is that I put the sub report in the Detail band, so when I query a databas

相关标签:
1条回答
  • 2021-01-01 07:38

    The Detail band will be generated as many times as the number of records you have in your main dataSet(populated by the top-level query).

    If you want to keep the subreport in the Detail band, which is normal by the way, you can do one of these things:

    • either have a dummy query that returns only one record, so that the Detail band generates only once. Then, pass the report connection to your subreport. You may have done that already. This way you can run your query independently of the main report.
    • or leave the report as-is and add your printWhen expression ($V{REPORT_COUNT}.intValue()==1) directly on the Detail band, not on the subreport. Please note that this is just an ugly hack that may affect the report performance. Your main query still returns a lot of data that you don't use so you should consider the other options.

    If you can move the subreport out of the Detail band, place it in a band that allows overflow like Title or Summary band. Then:

    • have your main dataSet's query empty so that no Detail band gets generated
    • set whenNoDataType="AllSectionsNoDetail" at the report level(in the <jasperReport> tag) so that all the other sections except the Detail get generated
    • exactly as in the first option above, pass the report connection to your subreport and work from there
    0 讨论(0)
提交回复
热议问题