Dynamic Switching Of Style

This recipe shows how to select style using JavaScript.

Steps taken:

  1. Create a report template (DynamicSwitchingOfStyle.rml) using the given datasource (FruitSales.ds).
  2. Define the following parameter in the “Report > Parameters” page:Name=Locale, Value=${Locale#choice(Arabic,French)#Arabic}
  3. Enter the following script into “Report Properties > Scripts > On Render Begin”:chosenStyle = “”;
    if (Properties.getProperty(“Locale”) == “French”) {
    chosenStyle = “Style 1”;
    }
    else if (Properties.getProperty(“Locale”) == “Arabic”) {
    chosenStyle = “Style 2”;
    }
    println(“Chosen Style >>” + chosenStyle);
  4. Define the following function in the “Functions > On Render Begin” page:setStyle(getStyle(chosenStyle));

To download the necessary files for this recipe, refer to the attached ZIP file.
DynamicSwitchingOfStyle.zip (3.9 KB)