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.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.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.
2.1.3 Add Event
Select cell A1 and add a click event, as shown in the figure below:
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:
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}'
2.2.2 Design table
Design the table as shown below, and drag the fields into the corresponding cells.
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:
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:
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.