This recipe demonstrates how to use JavaScript to define style. You need to make sure “Cache All Properties” is disabled in the Report Properties page (This will make rendering a bit slower).
*“Cache all properties” assigns the style values to the component once at the beginning of rendering, instead of every time the item is rendered - therefore dynamic styles would be ignored.
Therefore if it is only one or two values you want to change, it is best to change them explicitly rather than with a style.
Steps taken:
- Create a report template (JavaScriptToDefineSytle.rml).
- Add a Data Field (Type: Literal) into the blank area of “Section Header”.
- Enter the following script into “Field Properties > Scripts > On Render Begin”:setStyleName(“detail”);
- Enter the following script into “Field properties > Scripts > On Render End”:println(getStyleName());
To download the necessary files for this recipe, refer to the attached ZIP file.
JavaScriptToDefineStyle.zip (2.9 KB)