Jump to content
We've recently updated our Privacy Statement, available here ×

Conditional Style Based on TextField Value


railsgeek
Go to solution Solved by mmflynn,

Recommended Posts

  • 3 months later...
  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

I found your post while doing a little work on styles myself. Better late than never?

 

You should be able to solve your problem by creating a default style with a conditional expression.

 

E.g.:

1. Create a style named "normal" (or whatever)

2. Click Default style

3. Add a Style Condition

4. Write a boolean expression that would result "true" for all the fields you want to apply the style to. (I'm not very good at this part...)

5. Apply the new style to the fields you want to evaluate.

 

I'm not an expert, but this might help!

 

Mary

Link to comment
Share on other sites

hm, this is a good question. If I understand, you want a "dynamic" evaluation expression for your conditional style, based on the textfield value (that can be calculated based on different report objects, like fields, parameters, etc...). Like a generic style for numeri values...

Essentially this is not possible in JR: when you define the condition, the condition itself is compiled in a java expression that is independent by the element to which the style will be applied. This means that even if you find a way to parametrise the "result" of your textfield, there is no way to set a condition on his style dynamically.

 

The best way (already suggested) is create a parent style and specialize children styles for each expression you need as condition.

 

Giulio

Link to comment
Share on other sites

  • 4 years later...

I would like to create a style which in English would read:

If the value of the field I am in is less than zero, change the color to RED

Then when I apply that style to 10 number fields, I do not have to create a conditional style for each field.

If I had 3 fields, named "MEXICO_PROFIT", "USA_PROFIT", "CANADA_PROFIT", I currently see needing 3 conditional styles:

MEXICO_PROFIT_STYLE

$F{MEXICO_PROFIT} < 0

foreground RED

USA_PROFIT_STYLE

$F{USA_PROFIT} < 0

foreground RED

CANADA_PROFIT_STYLE

$F{CANADA_PROFIT} < 0

foreground RED

What I want is something like this, which I could apply to any numeric field:

NEGATIVE_RED_STYLE

$F{*} < 0

In this case $F{*} means the current field.

In Java you have the "this" object to get yourself, is there no way inside a conditional style expression to get the field where the style is being applied to?

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...