JS Display Different Content According to Device Types

  • Last update:January 15, 2021
  • I. Overview

    1.1 Problem description

    The desired effect is to display different content according to the devices.

    1.2 Solution

    1) Hide report content: using conditional formatting to control the row height of report content.  The row height of the content to be hided is set to 0mm.

    2) Judge device type: using After Initialization event to judge device

    II. Example

    2.1 Design report

    Create a new report,as shown below:

    image.png


    2.2 Add Widget

    Add a text widget nemed "type" and a query widget in the parameter pane, and set the text widget to be invisible.

    image (1).png


    2.3 Add event

    Add After Initialization event for text widget:

    image (2).png

    JavaScript as shown bellow:

    var self = this;
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r != null) return unescape(r[2]);
        return null;
    }
    if(!window.navigator) {
        self.setValue("Mobile");
    } else {
        op = GetQueryString("op");     
        if(op == 'h5') {
         self.setValue("H5");
        } else {
            self.setValue("PC");
        }
    }

    Information about parameter named op: Description of OP parameter


    2.4 Add conditional formatting

    Select A1~D8, add conditional formatting, and set line height to 0 mm.

    Enter formula: nvl(type,"H5") = "Mobile",and click button Add.

    For more information about conditional formatting you can refer to: An Introduction of Conditional Formatting

    image (3).png

    In the same way, add conditional formatting for A10~D14 but change the formula to:

    nvl(type, "H5") = "Mobile"


    2.5 Save and preview

    Save report.

    Preview the report in PC:

    image (4).png    

    Preview the report in the browser of mobile devices:

    image (5).png

    III. Report download

    Attachment List


    Theme: Secondary Development
    • 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