Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » BIRT » Determine Visibility of a Row in Script
Determine Visibility of a Row in Script [message #676260] Fri, 03 June 2011 12:49 Go to next message
No real name is currently offline No real nameFriend
Messages: 4
Registered: May 2011
Junior Member
Hello,

I am working on a customizable report in which vendor information is listed, each vendor can have up to 4 rows of data, with a blank row between each vendor. But it is customizable by the user, so it can have 1, 2, 3, or 4 rows of data per vendor. I want to highlight every other row Silver for easier readability. I originally had this code with a variable j = 0 set up once in the beforeFactory.

//this toggles between silver and white, every other line - in the "onCreate" script for each row
if (j == 0 ){
this.getStyle().backgroundColor = "Silver";
j = 1;
}
else j = 0;

The problem with this is that not all rows are visible so if I evaluate the following rows as the following colors:
1 Silver
2 White
3 Silver
4 White
5 Silver (blank space row)

Then, if only one row is selected to show by the user, it will be silver, and the blank row will be silver as well, giving an all silver report! I therefore want to know how to get a variable from the particular row that tells me whether its visibility rules evaluated to true or false. I have been researching some solutions and looking at the API and based on what I found, tried the following in the onCreate script for the first detail row:

TableHandle th = (TableHandle)reportContext.getDesignHandle().findElement("vendorMasterTable");
RowHandle rowHandle = (RowHandle)th.getDetail().get(0);
Iterator it = rowHandle.visibilityRulesIterator();
// and then somehow go through the rules and make sure they're all true before toggling the silver and white

The first line gives me a compile error: "missing ; before statement" and there's nothing before it! I'm not sure if this code doesn't go in the onCreate script of the row or if I need to import something, and after much research, I can't figure it out. I am pretty new to BIRT scripting so I may just be missing something that's obvious to you experts.

Thanks,
Meredith


Re: Determine Visibility of a Row in Script [message #676277 is a reply to message #676260] Fri, 03 June 2011 13:46 Go to previous messageGo to next message
Jason Weathersby is currently offline Jason WeathersbyFriend
Messages: 9167
Registered: July 2009
Senior Member

Meridith,

You are putting Java code in script which will not work. You can call
Java code from the script but your code will need to be modified:

for example, this:
TableHandle th =
(TableHandle)reportContext.getDesignHandle().findElement("vendorMasterTable");

to
var th = reportContext.getDesignHandle().findElement("vendorMasterTable");

An easier way of doing what you need is to use the
this.getStyle().visibleFormat property in the onCreate script. I wrote
up a quick example on this located here:

http://www.birt-exchange.org/org/devshare/designing-birt-reports/1370-alternating-colors-with-hidden-rows/

Essentially just add this script to your onCreate of the detail row:
if( typeof jj == 'undefined' ){
jj=0;
}
if( (this.getStyle().visibleFormat != "all") ){
if( jj !=0 ){
this.getStyle().backgroundColor="Silver";
jj=0;
}else{
jj++;
}
}

Jason

On 6/3/2011 8:49 AM, forums-noreply@eclipse.org wrote:
> Hello,
>
> I am working on a customizable report in which vendor information is
> listed, each vendor can have up to 4 rows of data, with a blank row
> between each vendor. But it is customizable by the user, so it can have
> 1, 2, 3, or 4 rows of data per vendor. I want to highlight every other
> row Silver for easier readability. I originally had this code with a
> variable j = 0 set up once in the beforeFactory.
>
> //this toggles between silver and white, every other line - in the
> "onCreate" script for each row
> if (j == 0 ){ this.getStyle().backgroundColor = "Silver";
> j = 1;
> }
> else j = 0;
>
> The problem with this is that not all rows are visible so if I evaluate
> the following rows as the following colors:
> 1 Silver
> 2 White
> 3 Silver
> 4 White
> 5 Silver (blank space row)
>
> Then, if only one row is selected to show by the user, it will be
> silver, and the blank row will be silver as well, giving an all silver
> report! I therefore want to know how to get a variable from the
> particular row that tells me whether its visibility rules evaluated to
> true or false. I have been researching some solutions and looking at the
> API and based on what I found, tried the following in the onCreate
> script for the first detail row:
>
> TableHandle th =
> (TableHandle)reportContext.getDesignHandle().findElement("vendorMasterTable");
>
> RowHandle rowHandle = (RowHandle)th.getDetail().get(0);
> Iterator it = rowHandle.visibilityRulesIterator();
> // and then somehow go through the rules and make sure they're all true
> before toggling the silver and white
>
> The first line gives me a compile error: "missing ; before statement"
> and there's nothing before it! I'm not sure if this code doesn't go in
> the onCreate script of the row or if I need to import something, and
> after much research, I can't figure it out. I am pretty new to BIRT
> scripting so I may just be missing something that's obvious to you experts.
>
> Thanks,
> Meredith
>
>
>
Re: Determine Visibility of a Row in Script [message #676306 is a reply to message #676277] Fri, 03 June 2011 15:16 Go to previous message
No real name is currently offline No real nameFriend
Messages: 4
Registered: May 2011
Junior Member
This works great! Thanks a lot. Smile
Previous Topic:How to sort cross tab by grand total column?
Next Topic:Problem with Charts - BIRT crashes
Goto Forum:
  


Current Time: Thu Apr 25 12:55:16 GMT 2024

Powered by FUDForum. Page generated in 0.03335 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top