Jump to content
Changes to the Jaspersoft community edition download ×

Stetch problem with long subreport


blackflame

Recommended Posts

Hi there

I'm creating a report with Ireports 3.7.5.
In my report there are two rectangles, one beside the other horizontally. In the left rectangle there is a static text and inside the right rectangle there is a subreport. I needed the first rectangle height to grow as much as the subreport do and I got it by setting the Stetch Type to Relative to tallest object.

Here it comes the problem: When the subreport is more than one page long, the left rectangle height only reaches the end of the first page, and there is no trace of it from the second page on. Something like this:
 

          (first page)
------------. -------------------------
| HELLO |     some data        |
|               |------------------------ |
|               |      some data       |
                             .
                             .
                             .
|               |       some data      |
|-------------------------------------

        (end of first page)

         (second page)

                 ------------------------
                 |      some data    |
                 | --------------------- |
                 |       some data   |

                            . . .
                  |____________|

         (end of second page - no trace of the left rectangle in this page)

 

How can I do  to make the first rectangle to fit the whole subreport height?

Thanks in advance!

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

As you have found out rectangles are only really useful if they don't overflow onto following pages. The solution is to use lines instead of rectangles.  There are some subtleties that need to be taken into consideration though.  Here's a description of how the example was put together.  Just adapt it to suit your needs

OK let's start with the layout of the report. The main report's Detail section will display some general information for each record in a box.  It will also display some detailed information in another box that must be contained entirely within the main report's box.  The detailed information may overflow onto one or more following pages.

First you contruct the basic layout of the main report's box, ignoring the subreport for now.  Instead of using a rectangle to frame the main display area we use two horizontal lines and two vertical lines.  The first horizontal line can define both the top border of the frame and the distance between each row of detail.  Simply create a horizontal line across the canvas at position y, where y is the measure of the gap that you want between each record.

Now place all of the main report's information elements (eg. Static Text, Text Boxes, etc) underneath that line.  Next you need to create another horizontal line below the main report's information elements, leaving enough space to insert a subreport element. The subreport only has to be a few pixels high because subreports expand by themselves, but it's a good idea to make it tall enough to visually understand what type of element it is.  The bottom line's Stretch setting needs to be set to FLOAT so it can be repositioned automatically as the subreport's size changes.  Join the outer edges of the top and bottom lines with two vertical lines.

Let's move on to the subreport now.  The canvas for the subreport does not need to have any margins, so set them all to 0.  Make sure the body of the subreport is exactly the same width as the body of the main report.  This makes it easier to line elements up as you will discover shortly.  Add all the information elements to the detail section of the subreport, then minimise the detail section to the smallest vertical size possible.  Create a horizontal line in the REPORT HEADER section and position it so that it's flush with the bottom of the section.  Now create a horizontal line in the LAST PAGE FOOTER section and position it at the very top of the section (y=0).

Now for the fiddly bits that make the whole thing work: the vertical lines.  First draw two vertical lines in the subreport's detail area that go from top to bottom and "join" the ends of the horizontal lines in the REPORT HEADER and LAST PAGE FOOTER sections.  Now add two more vertical lines in the exactly same position as the vertical lines of the main report.  These will provide side walls for the main report's "rectangle" for every row of detail.

To avoid nasty gaps appearing you will also need to create vertical lines in the exactly same position as the vertical lines of the main report in the REPORT HEADER and LAST PAGE FOOTER sections of the subreport.  They must go from top to bottom to form a continuum.  The size of the LAST PAGE FOOTER section will define the gap between the bottom of the subreport's rectangle and the bottom of the main report's rectangle.

NOTE: If the subreport has any GROUP or COLUMN sections then these will need to include vertical lines that replicate the vertical lines of the side walls of the rectangles in both the main report and the subreport.

Insert the subreport into the Detail section of the main report.  It should stretch from the left margin to the right margin.  It doesn't matter if it overlaps the vertical lines representing the side walls of the main report's rectangle.  It must not overlap any of the main report's information elements.  Reduce the vertical size of the subreport element to fit immediately above (ie. 1 pixel above) base of the rectangle in the main report.

Format the rest of the report as required.  Garnish and serve warm
 



Post Edited by jmurray at 10/29/2010 08:46
Link to comment
Share on other sites

jmurray,

Thanks for the example. It's very interesting.

For anyone else that might have similar requirements, I have tweaked the reports slightly. I just removed the hard-coded path to the subreport and modified the SQL queries so that they don't depend on any tables. Now they work in any MySQL database, and they will likely work without modification is other DBMSs too.

Regards,
Matt

Link to comment
Share on other sites

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...