JavaScript To Define Style

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:

  1. Create a report template (JavaScriptToDefineSytle.rml).
  2. Add a Data Field (Type: Literal) into the blank area of “Section Header”.
  3. Enter the following script into “Field Properties > Scripts > On Render Begin”:setStyleName(“detail”);
  4. 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)