views:

509

answers:

2

When using an aggregate control in some reports you would prefer to see a blank field instead of 0. There does not appear to be a way to do this automatically. Does anyone have a way that this can be done. Note, you want to maintain the '0' value for the field in cases when you export, but you want to show a blank when rendering to PDF or HTML.

+4  A: 

There are a number of ways to solve this. The two primary are to use either visibility rules or highlights to create conditional formatting. The visibility is particularly attractive since it is easy to only apply the format rules to particular types of output (e.g. HTML).

For this particular case, there are two problems with these approaches. First, I want a general solutions where I don't have to specify the text color. In other words, when the condition is true (value of 0) then I want my text color to match the background color. In that way if someone changes the backgroundColor for the control, the code still works.

The other issue is that in this case I am using dynamic column binding which does not support value lookup.

The solution that I created was to add a JavaScript function called hideMe as shown below.

function hideText (dataControl){
    if (dataControl.getValue() == 0) {
     var color = dataControl.getStyle().getBackgroundColor();
     var parentItem = dataControl.getParent();
     do {
      if (color == null && parentItem != null) {
       color = parentItem.getStyle().getBackgroundColor();
       parentItem = parentItem.getParent();
      } else {
       break;
      }

     } while (color == null);
     dataControl.getStyle().color = color;
    }
}

Once this function has been added to the report (in my case an included javascript file) I just call it from the OnCreate method of the control.

hideText(this);

This can also be done using Java Event Handlers but this method seems to be easier.

Scott Rosenbaum
A: 

Just an FYI, after working with this for a while longer, I have found that it is just easier to use Visibility rules. The one big advantage is that you can easily configure different visibility for different output formats. So for PDF it may be best to use blanks, but for Excel you may want the 0 values.

Scott Rosenbaum
Yes: I changed my mind.
Scott Rosenbaum