JS Realizes Batch Export Multiple Templates

  • Last update:March 25, 2021
  • I. Overview

    1.1 Expected Effect

    In actual business scenarios, you may encounter selecting data from the main table and exporting multiple sub-tables in the form of Excel, as shown in the following figure:

    1.gif


    1.2 Realization Ideas

    Add custom buttons to the main table, add click events to the buttons, get the checked checkboxes, and export the specified sub-tables in batches.

    II. Example

    2.1 Design Main Table

    2.1.1 Prepare data

    Create a new normal report, add dataset ds1, and the SQL statement is: 

    select * from ORDERS limit 10

    2.png

    2.1.2 Design table

    Design the table as shown below and drag the fields into the corresponding cells.

    • Cell A1: Add button widget, and customize the name of the widget.

    • Cell A3: Add a check button widget. Here, note that the left parent cell of the check button widget needs to be set to B3.

    3.png

    2.1.3 Add Event

    Select cell A1 and add a click event, as shown in the figure below:

    4.png

    The JavaScript code is as follows:

    var $span = $('.fr-checkbox-checkon');  
    var $tds = $("td").has($span);  
    var $trs = $("tr").has($tds);
    for (var i = 1; i < $trs.length; i++) {
    var name = $("td:eq(2)", $($trs[i])).find("div").html();  
    //alert(name);
    window.open("http://localhost:8075/webroot/decision/view/report?viewlet=Reuse%252FBatch_export_sub_table.cpt&op=write&id="+name+"&format=excel&extype=simple"+"&__filename__="+name);
    }

    2.1.4 Report Effect

    Save the report, rename it to Batch _export_main_table.cpt, click Data Entry Preview to preview the effect of the main table, as shown in the figure below:

    5.png


    2.2 Design Sub Table

    2.2.1 Prepare data

    Create a new normal report, create a new dataset ds1, the SQL statement is:

    select
    d.ORDERID,d.CUSTOMERID,d.SHIPMETHOD,d.SIGNDATE,dm.PRODUCTID,dm.PRICE,dm.QUANTITY 
    from ORDERS d
    left join ORDERSDETAIL dm on d.ORDERID=dm.ORDERID
    where d.ORDERID='${ID}'

    6.png

    2.2.2 Design table

    Design the table as shown below, and drag the fields into the corresponding cells.

    7.png

    2.2.3 Save Report

    Save the report, rename it to Batch_export_sub_table.cpt, click Data Entry Preview, and copy the URL of the sub-table to the code of the main table click event.


    2.3 Effect Preview

    Click to fill in the main form to preview, check several sub-orders, and click the Export button to export the corresponding sub-tables, as shown in the following figure:

    8.gif

    Note: Mobile terminal is not supported.

    III. Template Download

    The completed template can be found in:

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

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

    Click to download:

    Batch_export_main_table.cpt

    Batch_export_sub_table.cpt

    Note: If you find that you only export one Excel file after clicking, you need to set the browser’s forbidden pop-up window to allow if the code is correct.

    Attachment List


    Theme: Report Application
    • 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