Overview
Application Scenario
In practice, users may need to obtain data through a program. FineReport supports class datasets. After defining a custom class data source, users can add and use a Class dataset under the dataset section.
This document uses a simple example to explain how to define and use a class dataset. The example creates a custom simple data table through a Java program to generate a report.
Implementation Principle
The SimpleTableData abstract class defines attributes and methods related to data sources. To customize a class dataset, users can extend the SimpleTableData class when defining a class. This allows using its methods to define a class data source. Once defined, the FineReport report engine can read the defined data source for report generation.
Example
The following section demonstrates how to create a simple and custom class dataset. The data is shown in the following table.
| Name | Score |
|---|---|
| Alex | 15 |
| Helly | 22 |
| Bobby | 99 |
Preparing the Compilation Environment
Before compiling the program, create a Java development environment and install a Java IDE such as Eclipse or IntelliJ IDEA.
Import the FineReport project JAR packages into the IDE project, including:
All packages under FineReport installation directory/lib,
All packages under FineReport installation directory/server/lib,
All packages under FineReport installation directory/webapps/webroot/WEB-INF/lib,
and tools.jar under JDK. For detailed operations, see Compiling a Java Program.
Defining a Class Data Source
Writing a Java Program
Write the Java program SimpleArrayTableDataDemo.java in the IDE to define a class extending SimpleTableData, and define the data columns and data.
For complete code, see SimpleArrayTableDataDemo.zip.
Note:It is recommended that the package path of the file match the path in the code. If they do not match, ensure that the corresponding folder exists under the project path FineReport installation directory/webapps/webroot/WEB-INF/classes, as described in the section "Importing the Class File." Additionally, manually import SimpleTableData in the code by adding import com.fr.data.SimpleTableData;.
Compiling the Java File
After writing the Java program, compile SimpleArrayTableDataDemo.java in the IDE. Once compilation succeeds, the class file SimpleArrayTableDataDemo.class will be generated under the project storage path in the IDE, as shown in the following figure.

Importing the Class File
Copy the compiled class file SimpleArrayTableDataDemo.class to the project directory FineReport installation directory/webapps/webroot/WEB-INF/classes/com/fr/data, and restart the report project.
The class data source is now defined, as shown in the following figure.

Note:During remote design, the class file corresponding to the class dataset must be placed under the projects of both the local designer and the remote server.
Download the class file: SimpleArrayTableDataDemo.rar
Creating a Class Dataset
Click the
sign, click Class, and select the corresponding class file in the pop-up Class Dataset window, as shown in the following figure.

After selecting the class file, click OK to complete the class data source configuration.
Using the Class Dataset
After configuring the class data source, you can use the custom class dataset in the same way as other dataset types, for example, binding data fields to cells via drag-and-drop, as shown in the following figure.
