Dashboard Home

Exception Reporting - Stop Light - Row Banding

Exception Reporting - Stop Light - Row Banding

Dynamic Java Scripting is an extremely powerful tool. Beanshell scripting engine is embedded within InfoCaptor and this opens up tons of possibilities. One of the most important thing that you can do is exception reporting. You can create visual alerts by changing the color and fonts of the table cells based on the value it contains.

 

1 . Desired Output - Row bandingDesired Output - Row banding

Desired Output - Row banding

You have seen how to change and group colors for alternating rows but let us assume that the requirement is to group rows based on the value of a particular column.

 

In this example, the requirement is to have alternating colors based on the value of the "Indexes" column. You start with a color value say "Red" and if the value changes in the next row, then the next row should have a color value of "Blue" and again if the next row value changes then it should have "Red" and so on..

 

In the sample data above, the first two rows have the same value of "2" in the "Indexes" column so they both have font color as "Red". The third column has a different value of "1" and hence it has a color of "Blue".

 

This is achieved by manipulating the Java script component.

 

Enable the Dynamic Scripting and click on the "Dynamic Java Code"

 

2 . Java Script for value based Row bandingJava Script for value based Row banding

Java Script for value based Row banding

The column variable holds the column index on which our formatting is based on. In our case the "Indexes" column is the 11th column so we use a value of 10 as the column numbering starts at "0"

 

Next we assign, the two alternating colors

color1 = Color.red;

color2 = Color.blue;

 

You may use the following color values Color.black, Color.green, Color.cyan etc. Here is a list of default colors

 

If the default colors are not enough then you may specify new colors by providing the RGB values such as

color1 = new Color(102,34,140);

color2=   new Color(222,39,89);

 

 

If you need similar result then you don't have to modify the script further but if you need anything different then you may modify the script to suit your purpose.

 

Here is the complete script

 

column=10; //for the 1st col use 0, second use 1....11th column use 10 ( n-1)

Color color1=Color.red;

Color color2=Color.blue;

//if (colIndex==column)

{

 

    if ( rowIndex==0) //if the series is just starting then this variable will be null

  {

        prevColor=0; //set the initial color to red

        prevRowIndex=rowIndex;

       

 

  }

 

//     if (isNumeric)   //the current cell is numeric value

  {

              if (rowIndex==0)

            {

                  if (prevColor==0) renderer.setForeground(color1);

                  else renderer.setForeground(color2);

                  //prevValue=value;

            }

          else

          {

                   

                    prevValue= table.getValueAt(rowIndex-1,column);

                    colValue=table.getValueAt(rowIndex,column);

                  if ( !(prevValue.toString().equals(colValue.toString() )) ) //previous row is different than the current row

                {

 

                          if (prevRowIndex!=rowIndex) //if it is a different row then try to change the color

                        {

                                  if (prevColor==0) prevColor=1;

                                else if (prevColor==1) prevColor=0;

                          }

                           

                  }

                  if (prevColor==0) renderer.setForeground(color1);

                  else renderer.setForeground(color2);

                //////////////////////////////////////////////////////

                  if (table.isCellSelected(rowIndex,colIndex))

                    {

                          renderer.setForeground(Color.white);

                          renderer.setBackground(Color.blue);

                    }

                /////////////////////////////////////////////////////

                  prevRowIndex=rowIndex;

              // prevValue=value;

          }

           

  }

}