Philisophical Chunks

Its little world of author's intuitions.

Friday, June 10, 2011

BIRT - How to apply alternate background colors on Group Headers.

The below example is created from the Classic Models, Inc. Sample Database, and designed roughly :). Only titled question is focused.

First Way: Very easy and simple:
After applying group:
1) Select Script tab and  Set i = 0 in initiaze() method of report design.i could be any variable.


2. On the Layout tab of report select the Group header row (where you want to apply style) and then click on Script tab. Select onRender from Script drop down and write below script:

if (i==0) {
        this.getStyle().backgroundColor = "silver";
        i = 1;
    }
    else
    {
        this.getStyle().backgroundColor = "white";
        i = 0;
    }


That's all. Now run report.
For more: http://www.birt-exchange.org/org/devshare/designing-birt-reports/735-alternate-background-colors/#description

Second Way: A lengthy way:
Here is the one way to apply alternate row colors on the group headers in BIRT.
Below is the simple image of a Table having Customer Name, City, State, Order Number etc etc. Here Customers are being repeated because they have multiple Orders associated.Please note on below table (1.1) a highlight style is applied for alternate row.

Screen Shot 1.1
 Now see below image (1.2), here I grouped the data set for each Customer. Last three columns shows associated Order # with each customer, its date and Shipped Status.I also applied alternate row color for each group row, as you can see below that this alternate row color style isn't properly applied on group headers rows.
The reason of this is: Expression that is used is: if (row[0]+1)%2 = = 0 then highlight color will apply else NOT. And row[0] refers to the current row count of table,and the count of group main row and its first detail row is same, so its the reason of style disturbance.
Screen Shot 1.2
 
Below is one way to apply alternate row color style for group main rows:
Here we required to figure out the current group number. By row[0], we can not figure out group number.
Steps:
1. Double click on Data Set to Edit, then click on Computed Columns tab and then New to add a column:
Fill in the box as in the screen shot (1.3).
Screen Shot 1.3

















2. Then go in Binding Tab of Table's Property Editor. Click on Add Aggregation button and fill in box as in screen shot 1.4. Please note, select the group name from Group drop down on which you want to apply alternate color style.


Screen Shot 1.4





















3. Again click on Add Aggregation button and fill in as in Screen Shot 1.5.

Screen Shot 1.5



















4.  After step 3, select the Group Header row, and form the Property Editor click on the Highlights tab. Then click on add button.(Illustrated in 1.6)
Screen Shot 1.6
 5. In the Condition box, write this expression: row["current_group_num"]%2. Then selects Equal To form next drop down and set 0 in last field, choose background you want to set from Background Box and press OK. (Illustrated below in 1.7)
Screen Shot 1.7























6. Now run report, and see in figure 1.8 that groups are applied with proper alternate colors.



Screen Shot 1.8
P.S. If any one from readers have any better option/ way to achieve the above target, pls. do share. Any comments/suggestions/criticisms are more than welcomed.

6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. when i load report containing table in jsp page using AJAX then its takes some spaces between two rows. how i can control spaces between two rows of table in birt

    ReplyDelete
    Replies
    1. Manage the cell spaces in BIRT designer. try this and let me know if you still face the same issue.

      Delete
  3. thank you so much this is very useful

    ReplyDelete
  4. Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here. Apply Slotxo

    ReplyDelete