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

Where am I going wrong with grouping?


mathewrond

Recommended Posts

Hi,

I have a main report calling a subreport in the group. I see three different behaviours of <group> band

 

I use XML file as datasource

 

1.

Code:

<group name="DetailGroup">
<groupExpression><![CDATA[$V{REPORT_COUNT}]]></groupExpression>
<groupHeader>
<band height="8" isSplitAllowed="true" >
<subreport isUsingCache="true">
...

</group>

 

The above code just dumps all the records from the XML file to the report.

 

 

2.

Code:
[code]
<group name="DetailGroup" isStartNewPage="true">
<groupExpression><![CDATA[$F{PortfolioID}]]></groupExpression>
<groupHeader>
<band height="8" isSplitAllowed="true" >
<subreport isUsingCache="true">
...

</group>

 

 

The above code prints first record of every portfolio in separate page and ignores the rest of the records. Which means

I have 3 portfolio with 5 records each and jasper prints me first record of each portfolio in new page and ignores the rest

4 records in each portfolio.

 

 

3.

Code:
[code]
<group name="DetailGroup">
<groupExpression><![CDATA[$F{PortfolioID}]]></groupExpression>
<groupHeader>
<band height="8" isSplitAllowed="true" >
<subreport isUsingCache="true">
...

</group>

 

 

 

The above code prints first record of every portfolio in single page and ignores the rest of the records. Which means

I have 3 portfolio with 5 records each and jasper prints me first record of each portfolio in first page and ignores the rest

4 records in each portfolio.

 

 

The subreport uses <detail> band to display the records.

 

Can someone give me thoughts on it please?

 

Regards,

Mathew

Link to comment
Share on other sites

  • Replies 10
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

First Group: Your group expression is $V{REPORT_COUNT} which is a count of how many records are returned from your data source. Since it changes with every record, your group changes constantly, each record is being displayed.

 

Second/Third Group: You have isStartNewPage="true" which places each new group onto a new page. Also I suspect that you are printing the information in a band other than the detail band? Try moving the fields into the detail band of the main report and see if every record is printed.

 

HTH,

Robin

Link to comment
Share on other sites

Hi,

Thank you for your reply. The subreport is having all the text fields in the <detail> band only.

 

 

isStartNewPage="true" should be placing each group in a separate page but why is it placing each record into a new page? As I said earlier there are 5 records for the first portfolio it should actually display atleast 4 in one page and the rest in another page.

 

 

But this is not the case here. What do you say?

 

Regards,

Mathew

Link to comment
Share on other sites

That is how groups work... they combine the records so you can have detail bands that are related by the group expression. So if you have....

 

Fruit Type | Ammount | Color

Apple | 1 | Green

Apple | 43 | Blue

Apple | 24 | Orange

Grapes | 243 | Purple

 

And you group by $F{fruitType} as an expression, you would print group headers - detail band - group footer for $F{fruitType} = Apple and then you would have the same for $F{fruitType} = Grapes.

 

HTH,

Robin

Link to comment
Share on other sites

I hope there is no problem with this kind of group and it does what you have told

 

Code:

<group name="DetailGroup">
<groupExpression><![CDATA[$F{PortfolioID}]]></groupExpression>
<groupHeader>
<band height="8" isSplitAllowed="true" >
<subreport isUsingCache="true">
<reportElement
x="0"
y="0"
width="721"
height="8"
forecolor="#FFFFFF"
key="subreport2"
positionType="Float"/>
<subreportParameter name="PortfolioID">
<subreportParameterExpression><![CDATA[$F{PortfolioID}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<returnValue subreportVariable="REPORT_COUNT" toVariable="TradeCount" calculation="Sum"/>
<subreportExpression class="java.lang.String"><![CDATA["C:\projects\format1_subreport.jasper"]]></subreportExpression>
</subreport>
</band>
</groupHeader>
<groupFooter>
<band height="0" isSplitAllowed="true" >
</band>
</groupFooter>
</group>

 

And my subreport has got the details printed within <detail> band. Please correct me if I am wrong.

Link to comment
Share on other sites

Can you explain me what does this line mean please?

 

" if the sub-report is structured to stretch as needed "

 

How do we make sure that the subreport is getting stretched?

 

 

And you are right regarding the <group> band, I have refered to lot of jrxml files and all of them are same. The only difference is its working for them and not working for me :(

 

 

Any thoughts would be helpful.

Link to comment
Share on other sites

Sorry.. was thinking of another element re: stretch. The subreport should stretch automatically. To help you understand what is happening...

 

Think of the report as having two logical parts. The page structure parts (everything BUT the detail band) and then the "dynamic" part, which is the detail band ONLY. The detail band is printed once for every record in the datasource. When it is printed, it is combined with the other portions to create the produced output.

 

So a simple example.. 5 records...

 

A | 1 | test1

A | 2 | test2

A | 3 | test3

A | 4 | test4

B | 5 | test5

 

Our report structure is

 

GroupHeader1

Detail

GroupFooter1

 

Since we have 5 records... Detail band is printed 5 times and stacked one on top of another. The height of the group header/detailbands (1 instance for each record)/groupfooter are calculated and then bands are laid out on pages accordingly. So our pages consists of...

The group expression is "test", a constant value so the expression never changes and a new group never starts.

 

The output from this is....

Page1:

Group1Header

DetailBand For Record 1

DetailBand For Record 2

DetailBand For Record 3

(we ran out of room so a new page is started)

 

Page 2:

DetailBand For Record 4

DetailBand For Record 5

Group1Footer

 

As you can see, although the detail band was printed 5 times the group header band was only printed once, since the group expression hasn't changed. So if you were printing the field $F{field2} and expecting to see 1, 2, 3, 4, 5 you would only see $F{field2} value of "1" if you placed the field in the group header. This is because at the time the group header is evaluated and "printed" onto the page of the report, the 1st record is still the current record. Then the detail band is hit, and the records are iterated over and many detail bands are evaluated and "printed" onto the final report one on top of another (adding new pages as needed).

 

Now lets do the same thing, but change the group expression to be $F{field1}. Now the group expression will stay same for first 4 elements, then a new group will be started for the 5th element.

 

The report output will now be...

 

Group1Header (for $F{field1} = "A")

detail1

detail2

detail3

 

(new page is started since we ran out of room)

 

detail 4

Group1Footer (this is because the first 4 elements are in the same group remember.

 

 

IF isStartNewPage group option is on, we will go to a new page.. if it isn't we will stay on the same page. The rest of the report will be structured...

 

Group1Header($F{field1} = "B")

detail5

Group1Footer

 

 

So... if you have 5 data elements and your only seeing the first one, you have put the field into the group header which is only printed when the first record in your dataset is being used. If your group expression changes with every record (i.e. $V{REPORT_COUNT}) then you would see 5 records, each showing up in a group header. But this is NOT THE SAME group header.. it is 5 of them sequentially. (imagine a really thin detail/group footer seperating them.. height could even be 0 ... i.e. no group Footer). So it looks like it is printing all 5 fields, but it is printing them in 5 different groups.

 

HTH,

Robin

 

Post edited by: rsilver@bfm.bm, at: 2006/10/27 19:41

Post edited by: rsilver@bfm.bm, at: 2006/10/27 19:43

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