JS realizes batch printing/exporting of selected content

  • Last update:May 12, 2021
  • I. Overview

    1. Expected effect

    When exporting or printing in batches, check some rows and transfer the content to a new template for printing or exporting. The templates for different rows are different. As shown below:

    1.gif


    2. Implementation ideas

    Pass parameters through JavaScript code to print and export the specified template in batches.

    II. Example

    1. Subreport

    1) New test10001.cpt

    Create a new normal template, the template style is shown in the figure below:

    2.png

    2)New test10002.cpt

    Create a new normal template, the style is shown in the figure below:

    3.png



    2. Main report

    1) Data preparation

    Create a new normal template, create a new dataset ds1, the database query statement is: 

    SELECT * FROM Indent where 1=1 ${if(len(p1) == 0,"","and OrderID in ('" + p1 + "')")} limit 10

    As shown below:

    4.png

    2) Design report

    The report style is shown in the figure below:

    5.png

    3) Widget settings

    • Button widget

        Set cells C1 and C2 as Button, the button name of cell C1 is Batch printing, and the button name of cell C2 is Batch export. As shown below:

    6.png

    • Check button widget

        Select cell B3, click theWidget Setting, and set it as a Checkbox, as shown in the figure below:

    7.png

    Select cell B3, click Cell Attributes> Expand, set the Expansion Direction to No expansion, and customize the left parent cell as cell C3. As shown below:

    8.png

    • Setting parameter pane

        Edit the parameter pane, add a label widget,Drop-down Checkboxand queryButton. Set the control value of the label widget to p1:.

        Set the widget name of the Drop-down Checkbox to p1. Set the Data Dictionary, set the type to Data Query, the actual value and the displayed value are both the Order ID, as shown in the figure below:

    9.png


    3. Set up batch printing JS event

    Select cell C1, click Widget Setting>Event, add a Click event, and enter JavaScript code, as shown in the figure below:

    10.png

    The JavaScript code for batch printing is as follows:

    var printurl="http://localhost:8075/webroot/decision/view/report";
    var names = [];
    var paths = [];
    var singlepaths = [];
    var url = "ReportServer?reportlets=(";
    var $span = $('.fr-checkbox-checkon'); //Get the selected checkbox
    var $tds = $("td").has($span); //Define the cell of the selected check box
    var $trs = $("tr").has($tds);
    var p=[];
    for(var i=0; i<$trs.length;i++){
       var name = $("td:eq(2)",$($trs[i])).html(); //Get the value of the selected C4 cell
       var a = $("td:eq(3)",$($trs[i])).html();
       var b = $("td:eq(4)",$($trs[i])).html(); //
       names.push(name); //Put the selected value into the array
       var cptpath ="doc-EN/ReportApplication/FeaturesApplication/"+"test"+ name+".cpt";
       var urlstring = "{reportlet:" +"'"+FR.cjkEncode(cptpath)+"'"+",p1:"+"'"+name+"'"+",p2:"+"'"+a+ "'"+",p3:"+"'"+b+"'"+"}";
       debugger;
       paths.push(urlstring);
       debugger;
    }
    if(paths.length>0){
    var rpaths=paths.join(",");
    var reportlets="["+rpaths+"]";
    var config = {
    url: printurl,
    isPopUp: false,
    data: {reportlets:reportlets}
    };
    }
    debugger;
    FR.doURLPDFPrint(config);
    Show Code

    4. Set up batch export JS events

    Select cell C2, click Widget Setting>Event, add a Click event, and enter JavaScript code, as shown in the figure below:

    11.png

    The JavaScript code for batch export is as follows:

    var paths = [];
    var url = "report?reportlets=[";
    var $span = $('.fr-checkbox-checkon'); //Get the selected checkbox
    var $tds = $("td").has($span); //Define the cell of the selected check box
    var $trs = $("tr").has($tds);
    for (var i = 0; i <$trs.length; i++) {
    var name = $("td:eq(2)", $($trs[i])).html(); //Get the value of the selected C3 cell
    var a = $("td:eq(3)", $($trs[i])).html();
    var b = $("td:eq(4)", $($trs[i])).html();
    var cptpath = "doc-EN/ReportApplication/FeaturesApplication/" + "test" + name + ".cpt";
    var urlstring = "{reportlet:" + "'" + encodeURI(encodeURI(cptpath)) + "'" + ",p1:" + "'" + name + "'" + ",p2:" + "'" + a + "'" + ",p3:" + "'" + b + "'" + "}";
    paths.push(urlstring);
    }
    url = url + paths + "]&format=word&__filename__=Xname";
    window.open(encodeURI(url));
    Show Code


    5. Effect preview

    Save the template, click Data Entry Preview, you can print or export the data in the selected row according to different templates. The effect is shown in I.1 Expected effect.

    Note: The mobile terminal does not support various printing and exporting methods.

    III. Template download

    Please refer to the completed template:

    %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\ReportApplication\FeaturesApplication\PrintExample.cpt 

    %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\ReportApplication\FeaturesApplication\test10001.cpt

    %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\ReportApplication\FeaturesApplication\test10002.cpt

    Click to download the template:

    PrintExample.cpt

    test10001.cpt

    test10002.cpt

    Attachment List


    Theme: Report Application
    • Helpful
    • Not helpful
    • Only read

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

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

    不再提示

    7s后關閉

    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