How to print a grid report into other styles and format a report Print Style
We often need to print reports and encounter difficulties in printing them. For example, sometimes we don't want to strictly follow the style above the report and may have other styles suitable for actual application. What should we do at this time, in fact, the report software can be set. Today I will show you about it!
1. Problem Description
For a grid report, there is a check box before each line. You want to click the print button set on the page to print the values in the selected check box according to a certain style, such as columns and fixed display of several rows on the page.
2. Implementation ideas
You can define another template with a fixed format. The data in this template is filtered based on the values selected in the report, in a grid report, js needs to be defined in the Click Event of the button. js needs to first obtain the data of the selected row and then call FineReport (the report development tool used in the instance is FineReport) the built-in printing method adds the selected value to the URL of the printing method as a parameter to the printed template.
3. Example
The preview template is as follows:
Select some data and print it according to the style shown in. Next let's take a look at the specific implementation steps.
3.1 create a template to print the format
·Define a dataset
Since this template needs to be printed Based on the selected values, we need to define parameters in this template. Here we define parameters as dataset parameters.
Create a workbook and add the dataset ds1. The SQL statement is:SELECT * FROM order where order ID in ($ {ID }).
·Table Sample Design
Design the table sample to be printed. Here we set the template to the following style:
Set the left parent cell of cell B2 to none, and set the left parent cell of other cells to B2.
Set B3 and D3.
You can also split the Template into columns.
·Save Template
Save the template. For specific settings, refer to the template:% FR_HOME % \ WebReport \ WEB-INF \ reportlets \ doc \ Form \ FormFAQ \ PrintCol. cpt
3.2 modify preview Template
·Open Template
Open template:% FR_HOME % \ WebReport \ WEB-INF \ reportlets \ doc \ Form \ LineForm \ LineForm7.cpt.
·Modify template
In this template, we only need to modify the button name and the js of the button. Therefore, we can change the button name to "print" and modify js to the following code:
Var $ span = $ ('. fr-checkbox-checkon '); // obtain the selected check box var darray = []; var $ tds = $ ("td "). has ($ span); // obtain the cell for (var I = 0, len = $ tds. length; I <len; I ++) {// traverse the selected cell var id =$ ($ tds [I]). attr ("id"); // Add the id attribute var idn = id to the selected cell. replace ("A", "B"); // replace column A of the check box with column B of the customer ID var vv = document. getElementById (idn ). innerHTML; // obtain the data in column B of the selected cell. push (vv);} FR. dourlshortprint ("$ {sevletURL} ReportServer? Reportlet =/doc/Form/FormFAQ/PrintCol. cpt & ID = "+ darray); // call the print method. The URL is the template path prepared previously.
Note: If the obtained vv value is a string, you need to change it to darray. push ("'" + vv + "'") to put it into the array "'").
·Save Template
Save the template. For specific settings, refer to the template:% FR_HOME % \ WebReport \ WEB-INF \ reportlets \ doc \ Form \ FormFAQ \ PrintOtherStyle. cpt.
3.3 view results
Enter and preview PrintOtherStyle. cpt. After selecting a few rows of data, click the print button to print the data according to the effect.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.