官术网_书友最值得收藏!

Changing the title of the value prompt

In the previous example, the first line of the value prompt shows the data item name, that is, Month key (ship date) as shown in the following screenshot:

The business owners want to change this to a more generic and user-friendly text.

Getting ready

We will use the report generated in the previous recipe.

How to do it...

We need to add a line to the JavaScript from the previous recipe to change the text of first option (index 0). To do this perform the following steps:

  1. Open the prompt page of the report created in the previous recipe.
  2. Double-click on the HTML item that contains the JavaScript.
  3. Replace the code with the following:
    <script>
    var theSpan = document.getElementById("A1");
    var a = theSpan.getElementsByTagName("select"); 
    for( var i = a.length-1; i >= 0; i-- )  
      { var prompts = a[i];
      if( prompts.id.match(/PRMT_SV_/))
      { prompts.selectedIndex = 3;
        prompts.options[0].text = 'Choose Shipment Month'; /* This is the new line added to script */
      }     
      canSubmitPrompt();
    }
    </script>
  4. Run the report to test it as shown in the following screenshot:

How it works...

By default, the first line of a value prompt is the name of the data item. If you define the data item expression within brackets, that is, ([Sales (query)].[Time (ship date)].[Month key (ship date)]) in this example, then the first line of the value prompt is populated by the parameter name.

However, there is no property within Report Studio that would allow us to put a custom title. Hence, we are using JavaScript. We already know how to capture the prompt control using the GetElementsbyTagName function. Once it is captured, we can manipulate the values. We change the text property of the options[0] element to update the first line of the prompt.

There's more...

You can also use the REMOVE() function to remove particular lines of a value prompt. It is often useful to remove the first two lines (title and separator) using the following statements:

Prompts.remove(0);
Prompts.remove(1);
Prompts.removeAttribute("hasLabel");
主站蜘蛛池模板: 嘉义市| 乐陵市| 正镶白旗| 浦东新区| 沧源| 襄垣县| 潞城市| 汾阳市| 恩平市| 定安县| 南漳县| 大城县| 苏尼特左旗| 岚皋县| 永清县| 湖南省| 大兴区| 嘉祥县| 宁陵县| 和林格尔县| 新兴县| 伊春市| 平度市| 遵义县| 汪清县| 邢台县| 洪湖市| 奎屯市| 江安县| 山阴县| 莒南县| 隆昌县| 泗洪县| 澄城县| 吴旗县| 鹤岗市| 西丰县| 洛宁县| 东台市| 建平县| 澳门|