This example shows how to render a report from code. First, you need to add the Stimulsoft libraries and scripts, required for the component to work. All code should be added in the
<head>
block of the HTML page:
<?php
require_once 'vendor/autoload.php';
?>
...
<?php
$js = new \Stimulsoft\StiJavaScript(\Stimulsoft\StiComponentType::Report);
$js->renderHtml();
?>
Next, in the
<script>
block, create and configure an event handler:
<script type="text/javascript">
<?php
$handler = new \Stimulsoft\StiHandler();
$handler->renderHtml();
Finally, create and load a report, and call the
render()
method. 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. If required, the specified JavaScript function will be called after building the report:
$report = new \Stimulsoft\Report\StiReport();
$report->loadFile('reports/SimpleList.mrt');
$report->render();
$report->renderHtml('afterRender');
?>
...
function afterRender() {
alert('Done!')
}
</script>
На скриншоте ниже Вы можете увидеть результат выполнения данного кода: