Jump to content
Changes to the Jaspersoft community edition download ×

Recommended Posts

By: steve - georgeisbusting

using groups

2003-08-25 08:21

How would I use a group for a specific record? Is it possible to tell the reporting engine to use one group for the first few records in the datasource, and then use a different group for the next few records in the datasource, or does every record use every defined group? Thanks.

 

steve

 

 

 

 

 

By: Gary Hill - gary_hill94

RE: using groups

2003-09-03 08:03

I read your previous messages and I'm guessing the records you are dealing with have nothing in common to group them by. You simply want to do something based on the record number. You might be able to do what you want using a scriptlet. The scriptlet API has a method that is called before each deail line is evaluated and one called after each detail line is evaluated.

 

Try declaring a variable in your report something like this:

 

<variable name="record_count" class="java.lang.Integer" reset_type="Report" calculation="System">

<initialValueExpression>

new Integer(0)

</initialValueExpression>

</variable>

 

Create your own report scriptlet by extending the class JRDefaultScriptlet. Override one of the detail methods, probably callBeforeDetailEval. In your scriptllet you can increment the report variable with code similar to this:

 

Integer currentRecordCount = (Integer) this.getVariableValue("record_count");

Integer newRecordCount = new Integer(currentRecordCount.getIntValue() + 1);

this.setVariableValue("record_count", newRecordCount.)

 

This will give you a record_count variable in your report that you may be able to define groups with. Perhaps like this:

 

<group name="first">

<groupExpression>

record_count.getIntValue() < 2

</groupExpression>

</group>

 

I have not tested this exact code but I have done something similar. This should get you started anyway.

 

Gary

 

 

 

 

By: steve - georgeisbusting

RE: using groups

2003-09-04 13:11

Thanks for the help! I will try this. I actually made a group for every record. I know how many records there will be in the resultset, and used a static counter in the datasource object which I increment in the next() method. I store the counter in a variable like this:

 

<variable name="advance" class="java.lang.Integer" resetType="None">

<variableExpression>new Integer(CustomDataSource.COUNTER)</variableExpression>

</variable>

 

And then I access the counter in every group, and only print the specific group if I am on a specific line:

 

This is an example:

 

group name="TradeSales" isStartNewColumn="false">

<groupExpression>$V{advance}</groupExpression>

<groupHeader>

<band height="20">

<printWhenExpression><![CDATA[new Boolean($V{advance}.intValue() == 1)]]></printWhenExpression>

<textField>

<reportElement x="0" y="5" width="100" height="15" forecolor="#0000FF" />

<textElement textAlignment="Center">

<font reportFont="Times_Bold" />

</textElement>

<textFieldExpression class="java.lang.String"><![CDATA["Trade Sales">

</textFieldExpression></textField>

 

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

 

So if I am on the first record, then I the engine will print the first group, which contains "Trade Sales" as the first record label. Then within the group I print each column of the record. Using this method, I don't even use the <detail> section of the report at all. All records of the resultset are printed in groups. But I will try your method, because its a more elegant solution than mine. Mine will not work if I do not know how many records will be returned. Just for this specific report design, I do.

 

Thanks again for the help.

 

Steve

 

 

 

 

 

 

Steve

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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