开发者

JasperReports: subreport pagination

开发者 https://www.devze.com 2023-01-27 18:16 出处:网络
I\'ve been searching for a weeks for my problem on the internet, but I haven\'t found it yet, here is my problem, I wish anyone here can help me to solve this.

I've been searching for a weeks for my problem on the internet, but I haven't found it yet, here is my problem, I wish anyone here can help me to solve this.

Imagine I have the following data:

Customer
--------
cid : 1 | name: John  ;
cid : 2 | name: Smith ;

PhoneNumber
-----
cid : 1 | number: 1234 ;
cid : 1 | number: 5678 ;
cid : 1 | number: 4321 ;
cid : 2 | number: 6745 ;
cid : 2 | number: 3124 ;

I want to make a report with subreport inside it with the following requirements:

  • Customer ID -> 'cid' will use as report parameter
  • report only show one customer together with his/her phone number
  • One开发者_如何学C Page must only show one customer with one phone number

for example I took from customer details above with 'cid' = 1, it will generate 3 page because Customer with name "John" have 3 PhoneNumber.

Page 1:

Customer Name: John - Phone Number: 1234

Page 2:

Customer Name: John - Phone Number: 5678

Page 3:

Customer Name: John - Phone Number: 4321

My questions are:

  1. How I setup the Main Report to generate page according how many the subreport details?
  2. Which property I need to set on main report or subreport to fulfill my requirement?


1
Your main report query should return the phone numbers you want to show. Something like:

select phone_number from ... where cid=$P{CID}

Then you add a subreport in the Detail band, and give it the field value ($F{phone_number}) as a parameter. In the subreport, you can select more information about this second value.

2
Pagination is more tricky and not so easy to do with Jasper, but there are workaround.
In my project we make sure all bands are exactly the hight we want them. In your case - create the main report as you like it - with headers etc. and calculate the hight you need the detail band to be so it would take a whole page. Then make sure your subreport in exactly in this size.


very simple also you no need to take a sub report.

in main report write query like following

SELECT
cid,
(SELECT number FROM tablename WHERE tableid IN (SELECT tableid FROM tablename WHERE tableid=(SELECT min(tableid) FROM tablename WHERE cid=$P{parameter})
FROM tablename
WHERE cid=$P{parameter}

then make a new group of cid in iReport. clik on group band which you have recently created.see the report property for that band. clik on the start on new page check box.

place your two filed on that band. like

Cid number cidfield numberfield

then run report. the output coming is as you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号