Jump to content
We've recently updated our Privacy Statement, available here ×

Jasper Report - Only Print Group Header When At Least One Detail Fits On Page


furycomputers

Recommended Posts

I am creating a jasper report with some very specific requirements.

  1. The report contains a group.
  2. The group header must print at the beginning of the group and also on a new page.

This is not a problem since I just have to tell it to "Reprint Header On Each Page". So far so good.

  1. The detail section is not allowed to split across a page.
  2. The group header must not print at the bottom of a page unless at least one detail section will fit. (Could be rephrased as: The group header must only print when at least one detail section will fit)

At this point I noticed that there is a property for the group called "Min Height To Start New Page". This would be useful for a detail section of constant height, however...

  1. The detail section is dynamic height.

I have tried using "Keep together" on the group, but that can leave too much blank space on pages if the first group is small, but the second is large. It was rejected as a solution.

With these requirements in mind. All I am trying to do is not print the group header when the page cannot fit any detail entries.

I suspect that when it is filling in the report that it probably doesn't know the height of the detail section until it has filled it in, and by then it is too late. I'm hoping I am wrong.

I have tried recreating this report in two ways:

  1. One report with a group and detail sections.
  2. A main report with a subreport for the group, and within the subreport another subreport for the detail.

Both ways have led me to the same results.

Visually, if this was my data:

Province - Ontario
  City - Ottawa
  City - Toronto
Province - Nova Scotia
   City - Halifax
   City - New Glasgow
Province - Quebec
   City - Montreal
   City - Quebec City
  
 
I might get this result:
  
Page 1
Province - Ontario
  City - Ottawa
  City - Toronto
Province - Nova Scotia
   City - Halifax
   City - New Glasgow
Province - Quebec <- This hanging header is unwanted
 
Page 2
Province - Quebec
   City - Montreal
   City - Quebec City

I have tried many permutations of settings, placing the subreports in different bands, but I haven't found something that works. I am hoping someone knows of a combination of settings, placing subreports in different bands, etc. that will work.

Any idea how I might accomplish this?

 

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

This may be a bit of a hack but I would recommend you use several group headers, a sub-report (for City) and an ID for each (Province). This will allow for evaluation once per cycle.

Example:

1) Make each province ID from the database usable in the sql query

Province - Ontario          ID   = 1

Province - Nova Scotia   ID  = 2

Province - Quebec          ID  = 3

In order to make the IDs trigger for each iteration you can use group headers, as they are evaluated once per cycle - per say.

2) Now, insert some group headers more then one.

3) Then place a sub report (for you it would be the City) into the footer and pass into the 'Field' which is $F{ID}

 

This results in a sub report that triggers every time the header is evaluated, and the header will only print at the end of each sub-report.

 

Enjoy!

Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...