Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Table Background highlights using eventhandler
Happy_20
Hi
In my previous reports i have used event handler to highlight alternate rows in table. The code is a s follows:
public class TableCellBackgroundEventHandler extends RowEventAdapter {
private Integer count=0;
private static String grey = "#D8D8D8";
private static String white = "#FFFFFF";
public void onCreate(IRowInstance rowInstance, IReportContext reportContext) {
count++;
if (count % 2 == 0) {
rowInstance.getStyle().setBackgroundColor(grey);
} else {
rowInstance.getStyle().setBackgroundColor(white);
}
}
Now I have to highlight in the following pattern:
1
2
3-highlighted
4-highlighted
5
6
7-highlighted
8-highlighted
9
10
11-highlighted
12-highlighted
Can anyone please help me ?
Find more posts tagged with
Comments
mwilliams
"if (count%3 == 0 || count%4 == 0)" will find the two rows you want. Are you just doing one color now for the 3rd and 4th row? Or are you still alternating somehow?
Happy_20
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="74391" data-time="1299533269" data-date="07 March 2011 - 02:27 PM"><p>
"if (count%3 == 0 || count%4 == 0)" will find the two rows you want. Are you just doing one color now for the 3rd and 4th row? Or are you still alternating somehow?<br /></p></blockquote>
<br />
all the highlighted rows will be black in color and all the non-highlighted rows will be white in color.<br />
I need a fixed pattern for it.
Happy_20
<blockquote class='ipsBlockquote' data-author="'Happy_20'" data-cid="74400" data-time="1299536160" data-date="07 March 2011 - 03:16 PM"><p>
all the highlighted rows will be black in color and all the non-highlighted rows will be white in color.<br />
I need a fixed pattern for it. I don't know the count of the rows.It is dynamically generated. I want alternate two rows white and black.<br /></p></blockquote>
mwilliams
You would use a statement like the one I said above. If that statement is true, color black. else, color white.
Happy_20
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="74403" data-time="1299536937" data-date="07 March 2011 - 03:28 PM"><p>
You would use a statement like the one I said above. If that statement is true, color black. else, color white.<br /></p></blockquote>
The above condition will be satisfied only for 3rd and 4th row..again I want row 5 and 6 black, then 7 and 8 white, then 9 and 10 black..and so on<br />
<br />
I have used the following code which seems to be perfect, but still it is printing alternate row black and white. Don't know why<br />
<br />
public class TablePatternBackgroundEventHandler extends RowEventAdapter{<br />
<br />
private Integer count = 0;<br />
<br />
private static String grey = "#D8D8D8";<br />
private static String white = "#FFFFFF";<br />
<br />
public void onCreate(IRowInstance rowInstance, IReportContext reportContext)<br />
{<br />
<br />
count++;<br />
if (count % 2 == 0) {<br />
System.out.println("count increment" + count);<br />
Integer anotherCnt =0;<br />
do{<br />
<br />
anotherCnt++;<br />
System.out.println("another count 1st increment" + anotherCnt);<br />
rowInstance.getStyle().setBackgroundColor(grey);<br />
}while(anotherCnt<2);<br />
} else {<br />
Integer anotherCnt=0;<br />
do{<br />
anotherCnt++;<br />
System.out.println("another count 2nd increment" + anotherCnt);<br />
rowInstance.getStyle().setBackgroundColor(white);<br />
}while(anotherCnt<2);<br />
<br />
}<br />
}
mwilliams
You are right, I mixed it up a little. It needs to be something like:
if (count%4 == 3 || count%4 == 0){
black;
}
else{
white
}
If your row count starts at 0 instead of 1, it'd be 2 and 3 you'd be checking for rather than 3 and 0.
Hope this helps.
Happy_20
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="74434" data-time="1299595607" data-date="08 March 2011 - 07:46 AM"><p>
You are right, I mixed it up a little. It needs to be something like:<br />
<br />
if (count%4 == 3 || count%4 == 0){<br />
black;<br />
}<br />
else{<br />
white<br />
}<br />
<br />
If your row count starts at 0 instead of 1, it'd be 2 and 3 you'd be checking for rather than 3 and 0.<br />
<br />
Hope this helps.<br /></p></blockquote>
<br />
Thanks..it did
Happy_20
Need help again in the background highlight for crosstab
Please see the attached file (actual.pdf)
I need in help in first crosstab in the report (Region to Region Summary)
The Measures are in vertical dimension.
As you can see, every fourth row should be highlighted.
I wrote this code:
public void onCreateCell(ICrosstabCellInstance cell, IReportContext reportContext) {
try {
// For the header rows
if (cell.getCellType().equals("header")) {
if (cell.getDataValue("sourceRegion") != null) {
if (cell.getDataValue("sourceRegion") != headerValue) {
headerCount++;
headerValue = (String) cell.getDataValue("sourceRegion");
if (headerCount % 2 == 0) {
headerBackgroundColour = grey;
} else {
headerBackgroundColour = white;
}
}
}
cell.getStyle().setBackgroundColor(headerBackgroundColour);
}
// else { // if rows are not header rows, they are aggregation rows
// if (cell.getDataValue("targetRegion") != aggValue) {
// aggCount++;
// aggValue = (String) cell.getDataValue("targetRegion");
// if (aggCount % 2 == 0) {
// aggBackgroundColour = grey;
// } else {
// aggBackgroundColour = white;
// }
// }
// cell.getStyle().setBackgroundColor(aggBackgroundColour);
// }
}
catch (BirtException e) {
// No exception handling is required as execption get thrown if cells to not have attribute requested
}
}
}
I could get the first two columns highlighted the way I want ( see in sample.pdf)
Could not proceed further and so commented out the else part that highlights the aggregation rows.
Any help would be appreciated.
Thanks a lot
mwilliams
So, you want the measure rows associated with every other outer row dimension to be highlighted? Is this the case?
Happy_20
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="75975" data-time="1302902952" data-date="15 April 2011 - 02:29 PM"><p>
So, you want the measure rows associated with every other outer row dimension to be highlighted? Is this the case?<br /></p></blockquote>
<br />
yes you got it right. Can you guide me through it
mwilliams
What's your BIRT version again? I'll make a quick example.
Happy_20
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="75997" data-time="1303136482" data-date="18 April 2011 - 07:21 AM"><p>
What's your BIRT version again? I'll make a quick example.<br /></p></blockquote>
Birt Version - 2.6
mwilliams
Here's a way to do it. This example doesn't have just 4 inner rows for each outer dimension, it handles all amounts of inner rows per outer dimension. Let me know if you have questions.
Happy_20
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="76014" data-time="1303147929" data-date="18 April 2011 - 10:32 AM"><p>
Here's a way to do it. This example doesn't have just 4 inner rows for each outer dimension, it handles all amounts of inner rows per outer dimension. Let me know if you have questions.<br /></p></blockquote>
<br />
Thanks so much. It worked
<br />
<br />
Meanwhile I wrote eventhandler in java which also worked :<br />
<br />
public class CrossTabBackgroundInterNodalLatencySummary extends CrosstabEventHandlerAdapter {<br />
<br />
private Integer headerCount = 0;<br />
private String headerValue = "";<br />
private String headerBackgroundColour;<br />
private static String grey = "#CCEA97";<br />
private static String white = "#FFFFFF";<br />
<br />
@Override<
;br />
public void onCreateCell(ICrosstabCellInstance cell, IReportContext reportContext) {<br />
try { <br />
if (cell.getDataValue("sourceRegion") != null) {<br />
if (cell.getDataValue("sourceRegion") != headerValue) {<br />
headerCount++;<br />
headerValue = (String) cell.getDataValue("sourceRegion");<br />
if (headerCount % 2 == 0) {<br />
headerBackgroundColour = grey;<br />
} else {<br />
headerBackgroundColour = white;<br />
}<br />
}<br />
}<br />
cell.getStyle().setBackgroundColor(headerBackgroundColour); <br />
} <br />
catch (BirtException e) {<br />
// No exception handling is required as execption get thrown if cells to not have attribute requested<br />
} <br />
}<br />
<br />
<br />
}
mwilliams
Great! Glad to help!