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

Changing title of the dropdown box

In the previous example, the first line of value prompt shows the data item name, that is, Month key (Shipment date).

Changing title of the dropdown box

The business wants 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...

  1. We need to add a line to the JavaScript from the previous recipe to change the text of first option (index 0). For that, open the prompt page of the report created in the previous recipe.
  2. Double-click on the HTML item in the prompt footer.
  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.
How to do it...

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 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 GetElementsbyTagName function. Once it is captured, we can manipulate the values. We change the text property of options[0] element to update the first line of 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");
主站蜘蛛池模板: 南平市| 龙泉市| 舟山市| 兴业县| 临颍县| 会东县| 谷城县| 弋阳县| 察雅县| 乐陵市| 万源市| 清新县| 墨脱县| 六枝特区| 东台市| 平罗县| 改则县| 高淳县| 石门县| 永登县| 隆尧县| 吉水县| 寿宁县| 历史| 广河县| 静安区| 长海县| 观塘区| 双流县| 金山区| 鲁山县| 根河市| 宾川县| 永清县| 嵊州市| 安图县| 巴马| 准格尔旗| 荣成市| 齐齐哈尔市| 来宾市|