8
votes

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?

3

3 Answers

0
votes

You can't really prevent that becuase your detail band can be more than one page. However, you have a couple of options that you can try.

  1. Go to Group properties and set the "min height to start new page" to something like 200 or a value that meets your needs.

  2. Secondly, you can check the "print group header on each page" so that if your details section goes over a page then the header is repeated.

Hope this helps!

0
votes

To answer #4, preventing having a group header at the end of the page with no detail, this solution may work. You say in #5 that the detail section is dynamic in height. If you are referring to the height of the detail band, than I do not have a good solution. If you are referring to the number of detail entries in the detail section for a group, then the following solution should work.

Similar to what Fatih stated, set the "min height to start new page" setting to the number of pixels in height of your group header band, plus the number of pixels in height of the detail band. This will force the group header to print only on the next page if there isn't space for the group header and a single detail band.

I hope this helps.

0
votes

I had a similar situation with a report containing lots of subreports. Each subreport consist of a group header and detail band.

the problem I had sometimes the group header with appear in one page, then rest of the space will be a gap and the details of the subreport will appear in the next page. My subreport details was dynamic sizing in height.

The way I solved it is as follows:

Main report, I used to have splitType="Stretch" and I changed it to splitType="Prevent"

<detail>
    <band height="20" splitType="Prevent">
       <!-- this part contains all my subreports -->
    </band>
</detail>

For my subreports, I used to have minHeightToStartNewPage="200" which I removed (also using the keepTogether="true" did not work for me)

<group name="titleGroup">
    <groupHeader>
        <band height="20" splitType="Stretch">

For detail band in my subreport, the splitType remained as "Stretch"