Using Jasper ContitionalStyles with named style references - jasper-reports

I've got a situation where I create a report based on jrxml-files generated programmaitically and a style template with a given name and given style names. This works fine up to the point where there are conditional styles. Every example I found just uses ConditionalStyles to change some value like setting a different backcolor for specific situations. This can't be done here since there is no way of knowing what separates an even row style from an odd row style. Like wheter an odd row will get a gray background or an even row will get a green foreground and a black bottom pen.
What I tried or looked at:
Using Conditional Styles - There seems to be no way of defining a style reference just to change style values
Using a Variable for the style name - The variable didn't get evaluated
Creating a style with 2 ConditionalStyles using even and odd styles as parent styles - these were ignored when creating the jrtx-file
So... is there a way to create alternate styled rows using style references? If yes how it is done?

As there seems no solution to this, we had to change the structure of the style-files to include the conditional style instead of doing this in the document.
When walking this path and trying to change or create these style-files programmatically, be aware that in the JRXmlTemplateWriter that comes with Jasper, the method toWriteConditionalStyles is implemented as:
protected boolean toWriteConditionalStyles() {
return false;
}
Which is unfortunate. You'll have to use your own Exporter that changes this behavior.

Simply the way of knowing what separates an even row style from an odd row style.
Even row will satisfy the condition
(($V{REPORT_COUNT}%2) == 0)
Odd row will satisfy the condition
(($V{REPORT_COUNT}%2) != 0)
Then you can use a Conditional Styles with above conditions

Related

How can I change the font (not cell!) colour with an IF-condition?

I know how I can change the colour of a cell with the help of conditional formatting. But I would like to use a formula to achieve the following goal.
If a value <5.00% is entered into A2 via a formula, I want it to be displayed in Red 3. If it is >=5.00%, I would like it to be displayed in Green 3. Analogously, the same is true for A3/A4/A5 compared with B3/B4/B5.
STYLE is used for background colours.
I have also stumbled upon this solution, but it is suited for text replacement and not for my purpose. After creating two new custom styles, I have tried =T(STYLE(IF(A2<B2;"Red_if_lesser";"Green_if_greater_or_equal"))), but it has delivered an error (Err:522). What do I have to add to this formula in order to make it work?
For conditional formatting, it doesn’t matter if the cell value is calculated or it’s a fixed value. All you need to do is to define the appropriate rules for conditional formatting. In your case, you'll have to define two rules, one for current values < plan values, and one forcurrent values >= plan values. To change the font colour, define two new cell styles (can be done inside the conditional formatting dialogue), with an appropriate font colour:
Let’s start with the following data:
Select the cells that should be formatted based on their content. Pay attention that they are marked in this way:
Start defining the conditional formatting:
First rule: Cell value is less than B2 – apply a new style:
Set the Font Color for the new style in the Font Effects tab:
Add another formatting rule using the Add button – now with green font color:
Et voilà – the result:

Modify an ag-grid row after rendering

I need to slightly modify a ag-grid row after it has been rendered. In ag-grid, the actual HTML elements are not necessarily persistent, so manually-set styles may fall off.
For one thing, I have to modify the selection checkbox to set its tabindex to -1. This can technically be done in the cellRenderer callback, although it looks quite hacky. (The checkbox can be found at params.eGridCell.children[0].children[0].wrappedElement.)
But I also have to add a CSS class to some rows to highlight them based on external criteria. I haven't found a way to do this at all.
The best solution would seem to be using some sort of after-rendering callback, but to my knowledge no such thing exists.
I found a couple of related questions, but they were both resolved via cellStyle, which would not suffice here:
Row formatting in ag-Grid
How to provide a background color for an entire row in ag grid based on a certain value in a column?
You have not 1 but 3 options:
getRowClass(params):
Callback version of property 'rowClass'. Function should return a string or an array of strings.
getRowStyle(params):
Callback version of property 'rowStyle'. Function should return an object of CSS values.
processRowPostCreate(params):
Allows you to process rows after they are created. So do final adding of custom attributes etc.
In this last one you have the row in params.eRow.
All taken from https://www.ag-grid.com/javascript-grid-callbacks/index.php

Is it possible to capture checkbox selection(crossmark like X) on flatten pdf

I had an editable pdf with checkbox, after selection i flatten that pdf. from that flatten pdf i need to read the checkbox selection which is looks like crossmark(X), is there any possibility to read that checkbox selection.
When you flatten a PDF, you take away all interactivity. If you have a check box field in an interactive form, and you flatten that form, the check box field is gone. That is the concept of flattening.
What happens in practice?
A check box field has two appearances. One appearance is Off. This appearance can be a path such as a simple square defined as a rectangle. Another appearance can have any name On, Yes, 1 or whatever is defined in the original form. The corresponding appearance can be the same square as the Off appearance with two extra lines that look like a cross, or the square with a character that looks like a check mark, or whatever was defined in the original form.
When you flatten the form, you throw away the name of the check box field, you throw away the widget annotation that corresponds with the field, and you throw away one appearance state (depending on the value of the check box field). The only thing that is left, is one of the two appearances.
If you no longer have the original form, you have no clue as to what this appearance could look like, hence you have no idea what to look for, nor where to look for a specific appearance.
You say that the appearance looks like a cross mark in your case, but whoever reads this question has no idea if this cross mark is a path that was constructed in graphics state, or a glyph that was added in text state.
Long story short: if you flatten first and then expect to be able to read a field value, your design is seriously flawed.
You have to ask yourself: why do I need to flatten the form? Maybe it's sufficient to make the fields read-only. If that's not sufficient, why don't you add an attachment to the PDF that contains the original field values? There are many different ways to work around your problem.

GXT 3 spinnerField validation

I want to validate that user cannot change spinner value manually by typing in text box of spinner.
For example a field sales multiple = x which I fetched from server not fix.
and displays a spinner field with limitation of like bellow
spinner.setMinValue = x
spinner.setIncrement = x
spinner.setValue = x
so user forcefully select a value which is multiple with x. e.g. if x=3 the user have to enter 3,6,9... and so on.
So here my issue is if I type a 2 in spinner field text box. GXT widget accept that value.
Posible solutions:
Is there any predefined properties of spinnerfield that i forget to set it?
Is there any predefined validator for this?
Can I set text box of spinner field read only by css so user cannot focus on text box but still change a value.
If none of above how to achieve manually?
i've searched a bit in the different classes and I don't see either a precise method which would set what you want.
Don't know about one, and even with one, a validator doesn't change the value in the input field, but maybe it's enough for your needs.
You can disable the text input by calling setEditable(boolean) on the spinnerfield (testSpinner.setEditable(false);)
Maybe you could search around the IntegerPropertyEditor, I haven't tried but as long as a new Spinner is like this:
SpinnerField<Integer> testSpinner = new SpinnerField<Integer>(new NumberPropertyEditor.IntegerPropertyEditor());
you can seen that there is another Constructor for IntegerPropertyEditor, which takes a "NumberFormat" param, but there is no NumberFormart() constructor, so I'm not sure about how you create your own one, but that could be an idea (to format numbers in the input to be a multiple of the increment).
The last option would be that Sencha forgot this possibility and that you should report this as a "bug" on the forum ?
Hope to have helped a bit, good luck :).

Display blanks instead of 0 or 0.0 in a BIRT report

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.
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.
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.