I. Overview
1. version
Designer version |
---|
10.0 |
2. Problem description
Users sometimes need to achieve data backup and the data cannot be used in the business interface. How to achieve it?
3. Solution
Solving it by deleting logically. That is, add a column of "Status" in the table, and control the visibility or invisible of the data by changing the value of the Status column.
Filter data to display. That is, use the value of the "Status" field to restrict whether the data is displayed. For example, the original query statement is: select * from CUSTOMER, and the query statement after the status constraint is: select * from CUSTOMER where status="1".
II. Example
Take the CUSTOMER table in FRDemo as an example. Since there is no "Status" field in the table, the DISTRICT field is used as the mark.
When the value in the DISTRICT field is 1, it is normal data; when the value in the DISTRICT field is 0, it is deleted data.
1. Data preparation
Create a new general report, create a new dataset ds1, the SQL query statement is: select * from CUSTOMER.
2. Design report
Drag the data column in ds1 into the template, set the border for the table, align the text in the center, and set the color of the text in column F to red. The table style is as shown in the figure below:
3. Add button widget
Add a "Button" widget to cells G2 and H2, the button names are "Delete" and "Cancel delete" respectively. The steps are shown in the figure below:
4. Add click event
1) Select cell G2 and click "Widget Setting > Event" on the right to add a click event. The parameter row and parameter col are added to the click event, and the values are expressed by formulas as: row()-1 and col()-2. Enter the JavaScript code as follows:
FR.Msg.confirm("Tip", "Are you sure to delete?", function(value) {
if (value) {
contentPane.setCellValue(col, row, "0");
_g().verifyAndWriteReport();
} else {
contentPane.setCellValue(col, row, "1");
_g().verifyAndWriteReport();
}
})
The steps are shown in the figure below:
2) Select cell H2, click "Widget Setting > Event" on the right to add a click event. The parameter row and col are added to the click event, and the values are expressed by formulas: row()-1 and col()-3. Enter the JavaScript code as follows:
var v1 = contentPane.getCellValue(0, col, row);
FR.Msg.confirm("Tip", "Are you sure to cancel?", function(value) {
if (value) {
contentPane.setCellValue(col, row, "1");
_g().verifyAndWriteReport();
} else {
contentPane.setCellValue(col, row, "0");
_g().verifyAndWriteReport();
_g().parameterCommit();
}
});
As shown below:
5. Data entry attributes setting
Click the "Template>Data Entry Attributes", add a "Built-in SQL", select the "CUSTOMER" table in the FRDemo database, and add two fields "CUSTOMERID" and "DISTRICT" and the corresponding cells. As shown below:
Note: For the setting steps of data entry attributes, please refer to Data Entry Attributes.
6. Display setting
Select cell F2, click "Cell Attributes > Display", select "Formula Form", enter the formula: if($$$="1", "Normal", "Deleted"), which means if the current cell value is 1. It is displayed as "Normal", otherwise it is displayed as "Deleted".
7. Preview effect
Save the template and click "Data Entry Preview", the effect is shown in the figure below:
Note: Both App and HTML5 are supported.
III. Download template
Please refer to the completed template: %FR_HOME%\webapps\webroot\WEB-INF\reportlets\doc-EN\DataEntry\DataEntryApplication\Delete_logically.cpt
Click to download: