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

3

8

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?

Cene answered 10/12, 2014 at 15:24 Comment(0)
A
0

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!

Aerosphere answered 15/12, 2014 at 13:8 Comment(1)
I appreciate the answer, but you restated the two things I highlighted in my question as things I am already using or had already tried. See the highlighted sections where I list my requirements 1-5.Cene
A
0

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.

Autogiro answered 1/6, 2016 at 15:44 Comment(1)
Unfortunately in #5 I am referring to the height of the detail band.Cene
P
0

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"

Praetor answered 14/1, 2020 at 17:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.