JS implement custom options popover

  • Last update:  2021-11-03
  • I. Overview 

    1) Expected effect

    For reports with a large amount of data, you can use text widgets, button widgets, and cell check boxes to customize an option popup window for query, as shown in the following figure. Click the select button, and the data selection window pops up to process records.

    This method is recommended when a large number of drop-down options cannot be loaded.

    gif1.gif

    2) Implementation roadmap

    By passing parameter values through JS.

    II. Example

    1. Preparing a master template

    1) Data preparation

    Create a general report, create a dataset ds1, SQL statement is: SELECT * FROM Client

    1.jpg

    2) Table design

    •  Design the table as shown below and drag the field into the corresponding cell:

    2.jpg

    •  A3 cell property Cell Attributes>Display>Data dictionary>Database Table, select the "Client"table of the built-in database "FRDemoEN", the actual value is "CustomerID", and the displayed value is "Company_name", as shown in the figure below:

    3.jpg

    • Repeat and freeze the first two lines, as shown below:

    6.jpg

    3) Adding template parameters

    Click Template>Template Parameters, add a text type parameter and rename it "company_name", as shown below:

    5.jpg

    4) Setting cell filtering

    Add filter criteria for A3 cell elements: Select "CustomerID" for data column, "Contain" for operator, and "Parameter" for "$Company_name". The operation procedure is as follows:

    4.png

    5) Setting Parameters panel

    •  Edit the parameter panel, click "Add All" above the widget Settings on the right to generate the parameter widget, delete the "Company_name" label widget, click the parameter box, and select "Text widget", as shown in the following figure:

    7.jpg

    • Drag the "Button widget" to the parameters panel and set the button name to "..." , the operation steps are as follows:

    8.jpg

    •  Click "Button widget" to add "Click event", as shown below:

    9.jpg

    The JavaScript code is as follows:

    window.form = this.options.form;
    var $iframe = $("<iframe id='inp' name='inp' width='100%' height='100%' scrolling='no' frameborder='0'>");
    $iframe.attr("src", "${servletURL}?viewlet=doc-EN%252FParameter%252FJS_implement_custom_options_popover.cpt&op=write&__showtoolbar__=false");
    var o = {title : "Select information",width : 800,height: 300};FR.showDialog(o.title, o.width, o.height, $iframe,o);

    Note: where?viewlet=doc-EN%252FParameter%252FJS_implement_custom_options_popover.cpt&op=writeis the last part of? Viewlet = in the URL when the subtemplate is previewed, where &op=write indicates that the subtemplate is previewed.


    2. Preparing subtemplates

    1) Data preparation

    Create a common report and create dataset ds1. The SQL statement is :SELECT * FROM Client

    10.jpg

    2) Table design

    • Combine A1 cell with B1 cell, reduce row height of the second column, merge A3 cell with B3 cell, and retain A4 cell add "Checkbox", and then drag the field into the corresponding cell of B4~H4. The design is shown in the table below:

    11.jpg

    • B4 cellAttributes>Display>Data dictionary> Data Query, select dataset ds1, the actual value is "Customer ID", and the displayed value is "Company _name", as shown in the figure below:

    12.jpg

    •  Repeat and freeze the first two lines, as shown below:

    13.jpg

    3) Adding button widgets

    •  Add "Button widget" to cell A1, and set the button name to "Process selected records". As shown below:

    14.jpg

    •  Add "After initialization" event to "button widget", as shown below:

    15.jpg

    The JavaScript code is as follows:

    window.ceshi=[];
    • Add "Click" event to "Button widget", as shown below:

    16.jpg

    The JavaScript code is as follows:

    window.parent.form.getWidgetByName("公司名称").setValue(ceshi);
    window.parent.FR.closeDialog();
    window.parent.FR.destroyDialog();

    Note: The name of the assignment parameter must be the same as that of the main template parameter.

    4) Adding a check button widget

    Add "Checkbox" to cell A4, add "state change" event, set parameter a, the value is formula =B4, the operation steps are as follows:

    17.jpg

    The JavaScript code is as follows:

    var value = this.getValue();
    if (value == true) {
     ceshi.push(a);
    } 
    else if (value==false){
     ceshi.splice($.inArray(a,ceshi),1); 
    }

    3. Effect preview

    Save the master template and child template respectively. Click "Pagination preview" for the master template, and the effect is as shown below:

    gif1.gif

    Note: Mobile terminal is not supported.

    III. Download the template

    1) Master template

    For the completed template, see: %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\parameter\JS_implement_custom_options_popover_main.cpt

    Click to download the template: 

    JS_implement_custom_options_popover_main.cpt

    2)Subtemplate

    See  %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\parameter\JS_implement_custom_options_popover.cpt

    Click  to download the template: 

    JS_implement_custom_options_popover.cpt


    IV. Precautions

    In this paper, the "master template" uses cell filtering, and the "Subtemplate" returns the parameter type "Array". If SQL statements are used for parameter filtering without cell filtering, subtemplate must return "String" separated by ", "; otherwise, multi-value query cannot be performed.

    1) Change the master template database query statement to:SELECT * FROM Client where 1=1 ${if(len(Company_name)=0,""," and CustomerID in ('"+Company_name+"')")}  as shown below:

    18.png

    2) Modify the JS code for the "Click2" event in cell A1 of "Subtemplate".Change SetValue (ceshi) to setValue(ceshi.join("','")) As shown below:

    19.png

    3) Save the templates separately, click "Pagination Preview" for the master template, and the effect is as shown below:

    gif2.gif


    Attachment List


    Theme: Parameter
    Already the First
    • 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