JS 選択された内容をドロップダウンボックスの順番にする

  • 作成者:ayuan0625
  • 編集回数:12次
  • 最終更新:ayuan0625 于 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: FineReport カスタム開発
    • いいね
    • 良くない
    • 閲覧しただけ