JS Display selected items in order in the drop-down widget

  • Last update:  2020-12-15
  • I. Overview

    1.1 Problem

    In some actual reports, drop-down check boxes are often used, but the default drop-down check box values are displayed according to the order of selection.

    js-8.1.gif

    In some cases, the value of the selected items will need to be be sorted accordingly, as shown in the following figure. How to achieve this?

    js-8.2.gif


    1.2 Solution

    Use JavaScript to get all the items of the drop-down checkboxes, and after editing, sort the current checkbox values accordingly.

    Note: This method does not support the mobile devices.

    II. Example

    Add a drop-down checkbox widget to the parameter pane, and set the data dictionary.

    image.png

    Add the Edit End event to this widget. Enter the following JS:

    image (1).png

    var obj = contentPane.parameterEl.getWidgetByName('col').options.data.options.dataSource.data;
    //Get all options under the drop-down checkbox. "col" is the widget name
    var pArray = [];
    $.each(obj, function(i, v) {
        pArray.push(v.value);
    })
    //Store the items in pArray
    var v = this.getValue() + ''; //Get current values
    var cArray = [];
    cArray = v.split(','); //Split the array
    function isChild(element, index, array) {
        return cArray.indexOf(element) >= 0;
    } //Sort function
    var newArray = pArray.filter(isChild); //Store sorted values into new array
    this.setValue(newArray.toString()); //Turn array into string, and display it to the drop-down checkbox

    Save and preview the effect:

    js-8.2.gif

    III. Download template

    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