The report generator supports events that provide the ability to perform necessary operations before specific actions—both on the JavaScript client-side and the Python server-side. To call an event on the client-side, you need to add the name of the JavaScript function to the event as a string. To call an event on the server-side, you need to add the Python function itself to the event. Any number of functions, both client and server, can be added to a single event.

 

Example of adding multiple functions of different types to an event:

 

app.py

 

def prepareVariables(args: StiVariablesEventArgs):

   variables = args.variables

 

report = StiReport()

report.onPrepareVariables += prepareVariables

report.onPrepareVariables += 'prepareVariables'

report.onAfterRender += 'afterRender'

report.loadFile(url_for('static', filename='reports/SimpleList.mrt'))

report.render()

 

 

report.html

 

<script>

  function prepareVariables(args) {

      let variables = args.variables;

   }

 

  function afterRender(args) {

       alert("The report rendering is completed.");

   }

</script>

 

 

 

Depending on the event, the handler may operate on both the JavaScript client-side and the Python server-side simultaneously, or only on the JavaScript client-side. This is because the JavaScript core of the generator, which operates on the client-side, is used for building and exporting the report, while the server-side Python code is used for working with data, to which the JavaScript side doesn’t have direct access. Each event description will specify which handler can be used.

 

Some event arguments accept values from enumerations that are located in specific namespaces. All enumerations used in the report engine events are listed in the code block below:

 

app.py

 

from stimulsoft_reports.enums import StiDataCommand, StiDatabaseType, StiEventType

 

 

 

The report generator supports the following events:

 

onBeforeRender
onAfterRender
onPrepareVariables
onBeginProcessData
onEndProcessData

 

 

onBeforeRender

[v] JavaScript  [x] Python

 

The event is triggered before the report is generated. The list of properties passed in the event arguments on the JavaScript client-side:

 

Name

Description

event

Identifier of the current event, with the value  "BeforeRender".

sender

Identifier of the component that initiated this event, which can have the following values:

"Report"
"Viewer"
"Designer"

report

The current report object.

 

 

onAfterRender

[v] JavaScript  [x] Python

 

The event is triggered after the report is generated. The list of properties passed in the event arguments on the JavaScript client-side:

 

Name

Description

event

Identifier of the current event, with the value  "AfterRender".

sender

Identifier of the component that initiated this event, which can have the following values:

"Report"
"Viewer"
"Designer"

report

The current report object.

 

 

onPrepareVariables

[v] JavaScript  [v] Python

 

The event is triggered before the report is generated, after the report variables are prepared. The table below lists the event handler arguments on the JavaScript client-side:

 

Name

Description

event

Identifier of the current event, with the value  "PrepareVariables".

sender

Identifier of the component that initiated this event, which can have the following values:

"Report"
"Viewer"
"Designer"

report

The current report object.

variables

Collection of report variables and their values.

preventDefault

This flag allows stopping further event processing by the report generator. The default value is false.

 

 

The list of properties passed in the event arguments on the Python server-side. The arguments are of type StiVariablesEventArgs:

 

Name

Description

event

Identifier of the current event, with the value StiEventType.PREPARE_VARIABLES for this event.

sender

Identifier of the component that initiated this event, which can have the following values:

StiHandler
StiReport
StiViewer
StiDesigner

variables

Collection of report variables and their values.

 

 

onBeginProcessData

[v] JavaScript  [v] Python

 

The event is triggered before querying the data needed to generate the report. For file data sources, only the JavaScript event handler is supported. Below is the list of properties passed in the event arguments on the JavaScript client-side:

 

Name

Description

event

Identifier of the current event, with the value  "BeginProcessData".

sender

Identifier of the component that initiated this event, which can have the following values:

"Report"
"Viewer"
"Designer"

report

The current report object.

command

Identifier of the current command, which can have the following values:

"TestConnection" - checks the connection;
"ExecuteQuery" - queries data from the specified SQL source;
"GetSchema" - reads the XSD schema from the file source;
"GetData" - reads data from the file source.

connection

Name of the current data source connection specified in the report template.

database

Name of the current database, which can have the following values:

"XML"
"JSON"
"Excel"
"CSV"
"MySQL"
"MS SQL"
"PostgreSQL"
"Firebird"
"Oracle"
"MongoDB"
"ODBC"

dataSource

Name of the current data source specified in the report template. Set only for SQL data sources.

connectionString

Connection string to the SQL data source.

queryString

SQL query for data retrieval. Used only with the ExecuteQuery command.

pathData

Path to the data source file specified in the report template. Set only for XML and JSON data sources.

pathSchema

Path to the data schema file specified in the report template. Set only for the XML data source.

parameters

Collection of parameters and their values specified in the SQL data source.

preventDefault

This flag allows stopping further event processing by the report generator. The default value is false.

 

 

The list of properties passed in event arguments on the Python server-side. Arguments are of type StiDataEventArgs:

 

Name

Description

event

Identifier of the current event, with the value StiEventType.BEGIN_PROCESS_DATA for this event.

sender

Identifier of the component that initiated this event, which can have the following values:

StiHandler
StiReport
StiViewer
StiDesigner

command

Identifier of the current command, which can have the following values:

StiDataCommand.TEST_CONNECTION - checks the connection;
StiDataCommand.RETRIEVE_SCHEMA - queries the database schema for NoSQL data sources;
StiDataCommand.EXECUTE_QUERY - queries data from the specified SQL or NoSQL source;
StiDataCommand.EXECUTE - executes a stored procedure from the specified SQL source.

connection

Name of the current data source connection specified in the report template.

database

Name of the current database, which can have the following values:

StiDatabaseType.MYSQL
StiDatabaseType.MSSQL
StiDatabaseType.POSTGRESQL
StiDatabaseType.FIREBIRD
StiDatabaseType.ORACLE
StiDatabaseType.MONGODB
StiDatabaseType.ODBC

dataSource

Name of the current data source specified in the report template.

connectionString

Connection string to the SQL data source.

queryString

SQL query for data retrieval. Used only with the StiDataCommand.EXECUTE_QUERY command.

parameters

Collection of parameters and their values specified in the SQL data source. Values are always passed in their original (unescaped) form.

 

 

onEndProcessData

[v] JavaScript  [v] Python

 

This event is triggered after data is loaded and before the report is generated. For file data sources, only the JavaScript event handler is supported. Below is the list of properties passed in the event arguments on the JavaScript client-side:

 

Name

Description

event

Identifier of the current event, with the value  "EndProcessData".

sender

Identifier of the component that initiated this event, which can have the following values:

"Report"
"Viewer"
"Designer"

report

The current report object.

command

Identifier of the current command, which can have the following values:

"ExecuteQuery" - data retrieved from the specified SQL source.
"GetData" - data retrieved from the file source.

database

Name of the current database, which can have the following values::

"XML"
"JSON"
"Excel"
"CSV"
"MySQL"
"MS SQL"
"PostgreSQL"
"Firebird"
"Oracle"
"MongoDB"
"ODBC"

connection

Name of the current data source connection specified in the report template.

dataSource

Name of the current data source specified in the report template. Set only for SQL data sources.

dataSet

The prepared Stimulsoft.System.Data.DataSet, object containing tables and data rows from the file source.

result

A collection of columns and their types, along with data rows retrieved from the SQL source..

 

 

The list of properties passed in the event arguments on the Python server-side. The arguments are of type StiDataEventArgs:

 

Name

Description

event

Identifier of the current event, with the value StiEventType.END_PROCESS_DATA for this event.

sender

Identifier of the component that initiated this event, which can have the following values:

StiHandler
StiReport
StiViewer
StiDesigner

command

Identifier of the current command, which can have the following values:

StiDataCommand.TEST_CONNECTION - checks the connection;
StiDataCommand.RETRIEVE_SCHEMA - requests the database schema for NoSQL data sources;
StiDataCommand.EXECUTE_QUERY - queries data from the specified SQL or NoSQL source;
StiDataCommand.EXECUTE - executes a stored procedure from the specified SQL source.

connection

Name of the current data source connection specified in the report template.

database

Name of the current database, which can have the following values:

StiDatabaseType.MYSQL
StiDatabaseType.MSSQL
StiDatabaseType.POSTGRESQL
StiDatabaseType.FIREBIRD
StiDatabaseType.ORACLE
StiDatabaseType.MONGODB
StiDatabaseType.ODBC

dataSource

Name of the current data source specified in the report template. Set only for SQL data sources.

queryString

The final SQL query with all parameters used for data retrieval. Used only with the StiDataCommand.EXECUTE_QUERY command.

result

A collection of columns and their types, along with data rows retrieved from the SQL or NoSQL source.