I. Overview
1. Version
Designer Version |
---|
10.0 |
2. Expected effect
For multiple templates, users want to print them out with one click.
For dynamic parameter templates, users want to print reports with different parameter values in one click.
For example, there is a performance report of sales personnel across the country. After passing in the parameters of different regions, these reports are printed out in batches. As shown below:
3. Realization idea
Use JavaScript to call FineReport's print interface FR.doURLPrint(config) to print reports in batches.
II. Interface introduction
For the content of the FR.doURLPrint(config) print interface, please refer to Chapter 2 of the document JS Calls FR Print Method.
To realize batch printing, you need to set the data parameter in the interface. Data parameter form:
data: {
reportlets: "[{reportlet: 'reportname1.cpt',param1: 'value1',param2: 'value2'},
{reportlet: 'reportname2.cpt',param3: 'value3',param4: 'value4}]"
}
Note: The content in "[]" corresponds to the content that needs to be printed, a "{}" corresponds to a template, and the content in "{}" is separated by ",", the order is the template name, the parameter name in the template, if There are multiple parameters separated by ",".
Give examples of corresponding settings in different application scenarios:
1) Print the same template, the parameters of the incoming template are different
"[{reportlet: 'GettingStartedEN.cpt',Region: 'North China'},
{reportlet: 'GettingStartedEN.cpt', Region: 'East China'}]"
2) Print multiple templates, the name of the incoming template is different
"[{reportlet: 'GettingStarted001.cpt',Region: 'North China'},
{reportlet: 'GettingStarted002.cpt', Region: 'East China'}]"
3) Print the same template and pass in two parameters
"[{reportlet: 'GettingStarted.cpt',Region: 'North China',Salesperson: 'Sun Lin'},
{reportlet: 'GettingStarted.cpt', Region: 'East China',Salesperson: 'Zhang Shan'}]"
III. Example
1. Template preparation
1) Create a new datasetCreate a new normal report, create a new dataset ds1: SELECT * FROM Sales_Volume
2) Set parameter checkbox buttonDrag the area field into cell A2, select A2, and click the "Cell Element"> "Advanced" to customize the displayed value, as shown in the following figure:
Custom display value content:
'<input id="config1" type="checkbox" value="'+$$$+'" checked />'+$$$
Note: checked means that the parameter check boxes are all selected by default during initialization. If you don't need to be selected, remove this parameter.
In order to display A2 as a checkbox style, you also need to design its style to "Display by HTML".
Select A2, click "Cell Element> Other", and set the Display Content to "Display by HTML", as shown in the following figure:
Select A4, click "Widget Setting", and set it to "Button".
The button type is "Common" and the button name is "Batch Print", as shown in the figure below:
2. Set up batch printing JS event
Select cell A4, click "Widget Setting"> "Event", add "Click Event", and enter the JavaScript code, as shown in the figure below:
The JavaScript code is as follows:
var printurl = "http://localhost:8075/webroot/decision/view/report";
var p = [];
//Get the parameter value selected on the current page and put the value into the array
$(":checkbox").each(function() {
if ($(this).attr("checked") == "checked")
p.push("{reportlet:'GettingStartedEN.cpt', Region: "+ $(this).val() + "}");
})
if (p.length> 0) {
//Convert the array of parameter values into a string
var rp = p.join(",");
var reportlets = "[" + rp + "]";
var config = {
printUrl: printurl,
isPopUp: true,
// Whether to pop up the setting window, true means pop up, false means no pop up
data: {
reportlets: reportlets // list of templates to be printed
},
printType: 0, // Print type, 0 means zero client printing, 1 means local printing
// The following are the parameters for local printing, which only take effect when printType is 1
printerName:'Microsoft Print to PDF', // printer name
pageType: 2, // Print page number type: 0: all pages, 1: current page, 2: specified page
pageIndex: '1-3', // Page number range. Valid when pageType is 2
copy: 1, // print the number of copies
};
FR.doURLPrint(config);
} else
alert("Please select the parameters to be printed");
3. Effect preview
Save the template, click Data Entry Preview, you can print the selected button values in batches according to different parameters. The effect is shown in "Section I.2 Expected effect".
Note: Mobile terminal is not supported.
IV. Template download
Please refer to the completed template:%FR_HOME%\webroot\WEB-INF\reportlets\doc-EN\ReportApplication\FeaturesApplication\BatchPrint.cpt
Click to download: