Parameter Widget Display by JS Condition

  • Last update:November 07, 2024
  • Overview

    Version

    Report Server VersionFunctional Change

    11.0

    /

    Problem

    Sometimes, you may want to display some of parameter widgets in use only when conditions are met, as shown in the following figure. Namely, only after you select an option from the previous-level drop-down box, the next-level drop-down box will be displayed.

    JS根据条件显示参数控件 图1.gif

    Implementation Method

    First, you need to control the required widget to be invisible or disabled, and then add an editing end event by JavaScript scripts as a condition to the widget so that the controlled widget can be visible or enabled.

    API Description

    setEnable(boolean): It is used to determine whether to enable a widget. The option includes true (enabled) and false (disabled).

    setVisible(boolean): It is used to determine whether to visualize a widget. The option includes true (visible) and false (invisible).

    For API details, see General API for Widgets.

    Example

    Template Preparation

    Download the original template Multi-Value.cpt.

    The following figure shows the template parameter panel style.

    JS根据条件显示参数控件 图2.png

    In this template, use area as the condition widget and country as the controlled widget to illustrate the setting process.

    For details about how to query multiple values in a dataset, see Multi-Value Query by Dataset Parameters.

    Widget Hiding

    You need to hide country/city-related widgets first. In this way, the area widget is grayed out on the parameter panel during report initialization.

    1. Click the country drop-down box widget, choose Widget Setting > Attribute, and deselect Visible, as shown in the following figure.

    JS根据条件显示参数控件 图3.png

    2. Deselect Visible for the city drop-down box widget using the same method, as shown in the following figure.

    JS根据条件显示参数控件 图4.png

    3. Deselect Visible for the Country and City labels using the same method, as shown in the following figure.

    JS根据条件显示参数控件 图5.png

    Event Adding

    1. Select the area drop-down box widget and add an After Editing event. In this way, the country widget and Country label are visible after you select a value in the area widget, which is implemented by JS, as shown in the following figure.

    JS根据条件显示参数控件 图6.png

    The following content shows the JavaScript codes.

    var country = this.options.form.getWidgetByName("country");//Get the drop-down box widget country.
    var area = this.options.form.getWidgetByName("area");//Get the drop-down box widget area.
    var thislen = this.getValue().length;//Get the length in the value of the widget area.
    //If the length has been set for the widget area, the widget country and label Country are visible. If not, they are invisible and “Select a region.” is displayed.
    if(thislen) {
        country.setVisible(true);
        this.options.form.getWidgetByName("label3").setVisible(true);
    } else {   
        country.setVisible(false);
        this.options.form.getWidgetByName("label3").setVisible(false);
        alert("Select a region.");
    }

    2. Add an After Editing event for the country widget using the same method, as shown in the following figure.

    JS根据条件显示参数控件 图7.png

    The following content shows the JavaScript codes.

    var city = this.options.form.getWidgetByName("city");//Get the drop-down box widget city.
    var country = this.options.form.getWidgetByName("country");//Get the drop-down box widget country.
    var thislen = this.getValue().length;
    //If the length has been set for the widget country, the widget city and label City are visible. If not, they are invisible and “Select a country.” is displayed.
    if(thislen)
    {
    city.setVisible(true);
    this.options.form.getWidgetByName("label5").setVisible(true);
    }
    else {
        city.setVisible(false);
        this.options.form.getWidgetByName("label5").setVisible(false);
        alert("Select a country.");
    }

    Effect Preview

    Save the template and click Pagination Preview. The following figure shows the preview effect on the PC.

    JS根据条件显示参数控件 图8.gif

    iconNote:
    The function is not supported on mobile terminals.

    Template Download

    For details, you can download the completed template Parameter Widget Display by JS Condition.cpt.

    Attachment List


    Theme: Parameter
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy