-
Notifications
You must be signed in to change notification settings - Fork 21
/
Rendering a Report from Code.php
69 lines (57 loc) · 2.22 KB
/
Rendering a Report from Code.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
require_once '../vendor/autoload.php';
use Stimulsoft\Report\StiReport;
// Creating a report object and set the necessary javascript options
$report = new StiReport();
$report->javascript->relativePath = '../';
// Defining report events before processing
// It is allowed to assign a PHP function, or the name of a JavaScript function, or a JavaScript function as a string
// Also it is possible to add several functions of different types using the append() method
$report->onAfterRender = 'onAfterRender';
// Processing the request and, if successful, immediately printing the result
$report->process();
// Loading a report by URL
// This method does not load the report object on the server side, it only generates the necessary JavaScript code
// The report will be loaded into a JavaScript object on the client side
$report->loadFile('../reports/SimpleList.mrt');
// Calling the report build
// This method does not render the report on the server side, it only generates the necessary JavaScript code
// The report will be rendered using a JavaScript engine on the client side
$report->render();
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon">
<title>Rendering a Report from Code</title>
<style>
html, body {
font-family: sans-serif;
}
</style>
<?php
// Rendering the necessary JavaScript code of the report engine
$report->javascript->renderHtml();
?>
<script>
// The function will be called after building the report
function onAfterRender(args) {
// Displaying a message with the number of built report pages
document.getElementById("message").innerText = "The report rendering is completed. Pages: " + args.report.renderedPages.count;
// Saving the report as a JSON string
document.getElementById("reportJson").innerText = args.report.saveDocumentToJsonString();
}
</script>
</head>
<body>
<h2>Rendering a Report from Code</h2>
<hr>
<?php
// Rendering the HTML part of the report engine
$report->renderHtml();
?>
<div id="message"></div>
<pre id="reportJson"></pre>
</body>
</html>