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

Sort data within a group (alphabetically) between 2 columns (taking page breaks into consideration)


javalogan
Go to solution Solved by Tom C,

Recommended Posts

At the moment I have something like the following:

  • Grouped by CHILDREN
  • Data sorted alphabetically (top to bottom / left to right)
  • 2 columns of data (distributed evenly between both columns - last column might have one name less if the array is of an odd numbered size)

--------------------------------------------

(GROUP) CHILDREN - GIRLS

Claire                   Rosy

Evelyn                  Stephanie

Jessica                Tara

Kylie                     Tracy

Margret                Vanessa

Olivia                    Vivian

--------------------------------------------

 

PROBLEM:

When there is a page break for the group, the data still just flows within the columns over the pages as follows:

--------------------------------------------

(GROUP) CHILDREN - GIRLS

Claire                   Rosy

Evelyn                  Stephanie

Jessica                Tara

<PAGE BREAK>

CHILDREN - GIRLS (CONTINUED)

Kylie                     Tracy

Margret                Vanessa

Olivia                    Vivian

--------------------------------------------

SO NOW WE HAVE:

Page 1: Column 1: C > J

Page 1: Column 2: R > T

Page 2: Column 1: K > O

Page 2: Column 2: T > V

 

REQUIREMENT:

When there is a page break for the group, the COLUMN data should not flow over pages but should first display it alphabetically on the first page (between the two columns) and then continue on the second page alphabetically again.

--------------------------------------------

(GROUP) CHILDREN - GIRLS

Claire                   Kylie

Evelyn                  Margaret

Jessica                Olivia

<PAGE BREAK>

CHILDREN - GIRLS (CONTINUED)

Rosy                     Tracy

Stephanie            Vanessa

Tara                      Vivian

--------------------------------------------

SO NOW WE NEED...

Page 1: Column 1: C > J

Page 1: Column 2: K > O

Page 2: Column 1: R > T

Page 2: Column 2: T > V

 

CURRENT DATA:

Currently to get the data I do the following:

  • Populate an alphabeticalList containing all the girls
  • Use some processing to split the list into two lists
    • column1List
      • Claire
      • Evelyn
      • Jessica
      • Kylie
      • Margaret
      • Olivia
    • column2List
      • Rosy
      • Stephanie
      • Tara
      • Tracy
      • Vanessa
      • Vivian
    • Add each list to a subreport.
      • column1List assigned to COLUMN1(subreport) in detail band
      • column2List assigned to COLUMN2(subreport) in detail band

 

QUESTION:

Is there ANY way that I can achieve this? Either through Java before I send it to Jasper, or on the iReport side? Maybe even a scriptlet? 

I need the data to sort alphabetically in a group between the two columns, but if there is going to be a page break it needs to know how much data it can fit in on the page in the group before the page break so that the alphabetical list does not continue to the next page but rather first go to the next column... and then on the next page it should continue as normal. Explaining this sounds confusing so I hope my explanations above are more clear.

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

Forget about getting your data in two columns - instead, let JasperReports handle the two column layout. Merging your data into one column, sorting the data in alpha order, then displaying them in report in a two column layout:

 

<jasperReport ...... columnCount="2" ......>[/code]

 

Link to comment
Share on other sites

Thanks for the help Tchen.

This works... but then the only problem is that the column data is only distrubted evenly before the page break. After the page break it only fills column 1 (unless it reaches the end of the page again and then starts to fill column 2 from the top).

So we get the following (first part of the group starts close to the end of the page - which is why it overflows to the next page)

(GROUP) CHILDREN - GIRLS

Claire                   Kylie

Evelyn                  Margaret

Jessica                Olivia

<PAGE BREAK>

CHILDREN - GIRLS (CONTINUED)

Rosy                     

Stephanie            

Tara                      

Tracy

Vanessa

Vivian

--------------------------------------

I need the data that follows onto the next page after the page break to also distribute evenly between the columns even if it does not reach the end of the page...

Basically, the data needs to distribute evenly between the columns all the time and not only before a page break.

Even a normal group which fits on one page (no page break) needs to be distributed evenly instead of first filling the first column till the end of the page and then only starting to fill column2.

Link to comment
Share on other sites

  • Solution

The proposed approach only works in a single page. Sorry that my sample report might be misleading since it was based on the specific data provided in your question that happens to have report data evenly divided among two report pages thus a fix page height can be applied to both page layouts. In general, JasperReports engine is not able to help layout the report based on your requirement because:

1) report height is defined at design time and cannot be changed during report execution;

2) multiple column report layout is based on the available space in the section to determine the column height. It is not capable of auto adjusting the column height to display report content evenly among multiple columns.

There's no simple solution to meet your design requirement using JasperReports product. The pixel measurement used in JR report layout, compounded by field overflow stretch, makes it impossible to determine how many characters can fit into a report page in order to evenly layout field content in multiple column with one pass data processing.

Link to comment
Share on other sites

Currently JasperReports product is not able to provide the layout as per your design requirement due the complex nature of the process as briefly mentioned in the above posting. I have discussed the issue with our product gurus and confirmed there's no simple configuration using existing JR features to meet this requirement.

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