Hyperlink Click to Open a Report in a Dialog Box and Pass Parameters by JS

  • Last update:March 27, 2025
  • Overview

    Problem

    In some special scenarios, when opening the report in a dialog box by clicking a hyperlink (for example, clicking a button to realize a hyperlink jump) cannot meet the requirements, you can use the custom JS to open a report in a dialog box, as shown in the following figure.

    1.gif

    Implementation Method

    You can use the built-in FineReport JS methods showDialog, doHyperlinkByPost, or doHyperlinkByGet to open the report.

    Example One

    Report Design

    Create a template and enter Open Report in cell B2, as shown in the following figure.

    image 1.png

    JS Code Adding

    Select cell B2 and choose Hyperlink > JavaScript, as shown in the following figure.

    image 2.png

    Use the showDialog code as follows:

    iconNote:

    1. You can adjust the template path in the code according to the actual location of the template. You can also adjust the height and width of the dialog box. For details, see code comments. The parameter names need to be consistent with those of the opened template.

    2. If the Video Playback Plugin is used in a dialog box to play videos, after the template preview, the video may continue to be played even when  the dialog box is closed. In FineReport 11.0.2 and later versions, you can solve the problem by the following destroyOnClose:true code.

    //Template path.
    var url = encodeURI(encodeURI("/webroot/decision/view/report?viewlet=GettingStartedEN.cpt&op=view&Region=California"));
    //Iframe.
    var $iframe = $("<iframe id='inp' name='inp' width='100%' height='100%' scrolling='no' frameborder='0'>");
    //Set the src attribute of the iframe to the template path.
    $iframe.attr("src", url);
    //Iframe attribute.
    var o = {
        title: "Dialog Box",    //Title.
        destroyOnClose:true,   //Determine whether to remove the dialog box from dom when the dialog box is closed.
        width: 1000,         //Width.
        height: 700,        //Height.
        //closable:true,    //Determine whether to display the closing button. The default value is true.
        //confirm:true,     //Determine whether to add the button for confirming cancellation. The default value is false.
        //draggable:true   //Determine whether dragging is allowed. The default value is true.
    };
    //Iframe pop-up.
    FR.showDialog(o.title, o.width, o.height, $iframe, o);

    Show Code

    When you use the built-in JS method showDialog to open a dialog box by clicking a hyperlink, you can modify the style of the dialog box by adding code to modify the style behind the code.

    image 3.png

    iconNote:
    The following code used to modify the style of the dialog box can only be used in general reports. If you need to use the code in FRM reports, you need to use F12 to obtain the corresponding elements and modify the code.

    1. Centering the title

    $('.fr-core-window-header ').css("text-align""center");

    2. Modifying the background color of the title

    $('.fr-core-window-header ').css("background","red");

    3. Hiding the closing button of the window in the upper right corner of the dialog box

    $('.fr-core-panel-tool-close').hide();

    4. Removing the title text of the dialog box

    $('.fr-core-panel-title').hide();

    5. Modifying the color of the title text of the dialog box

    $('.fr-core-panel-title').css("color","blue")

    6. Modifying the top corner of the dialog box from rounded to square

    $('.fr-core-window').css("border-radius""0 0 0 0");
    $('.fr-core-window-header').css("border-radius""0 0 0 0")

    Effect Display

    Save the report. The effect is the same as that shown in section "Problem".

    iconNote:
    The effect cannot be previewed on mobile terminals.

    Example Two

    Report Design

    Same as section "Report Design" in "Example One".

    Code Adding

    Select cell B2 and choose Hyperlink > JavaScript, as shown in the following figure.

    image 4.png

    Use the doHyperlinkByPost code as follows:

    FR.doHyperlinkByPost({
    //Report path.
    "url":"/webroot/decision/view/report?viewlet=GettingStartedEN.cpt",    //Parameter.
    "para":{
    "__pi__":true,    //Determine whether to display the parameter panel.
    "Region":"California"
    },
    "target":"_dialog",    //Open the report in a dialog box.
    "feature":{
    "width":1100,
    "height":800,
    "isCenter":true,     //Determine whether to center the dialog box.
    "title":"Title"
    }
    })

    Show Code

    Effect Display

    Save the report and click Pagination Preview. The effect is the same as that shown in section "Problem."

    Example Three

    Report Design

    Same as section "Report Design" in "Example One".

    Code Adding

    Select cell B2 and choose Hyperlink > JavaScript, as shown in the following figure.

    image 5.png

    Use the doHyperlinkByGet code as follows:

    FR.doHyperlinkByGet({
    //Report path.
    "url":"//webroot/decision/view/report?viewlet=GettingStartedEN.cpt",    //Parameter.
    "para":{
    "__pi__":true,    //Determine whether to display the parameter panel.
    "Region":"California"
    },
    "target":"_dialog",    //Open the report in a dialog box.
    "feature":{
    "width":1100,
    "height":800,
    "isCenter":true,     // Determine whether to center the dialog box.
    "title":"Title"
    }
    })
    Show Code

    Effect Display

    Save the report and click Pagination Preview. The effect is the same as that shown in section "Problem."

    Template Download

    For details, you can click to download templates Example 1.cptExample 2.cptExample 3.cpt.

    Attachment List


    Theme: Report Features
    Already the First
    Already the Last
    • Helpful
    • Not helpful
    • Only read

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

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

    不再提示

    8s后關閉

    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