Using Viewer Events
Our sample projects and report templates can help you learn the basics of working with our products.This example shows how to use the report viewer events. Some viewer actions have events to which you can subscribe. For example, print action, begin of the export, design report:
In the screenshot below you can see the result of the sample code:

<script type="text/javascript">
// Enable the design button
var options = new Stimulsoft.Viewer.StiViewerOptions();
options.toolbar.showDesignButton = true;
// Create the report viewer
var viewer = new Stimulsoft.Viewer.StiViewer(options, "StiViewer", false);
// Assign the onGetReportData event function
viewer.onBeginProcessData = function (args) {
var ds = new Stimulsoft.System.Data.DataSet("Demo");
ds.readJsonFile("../reports/Demo.json");
args.report.regData("Demo", "Demo", ds);
}
// Assign the onPrintReport event function
viewer.onPrintReport = function (args) {
}
// Assign the onBeginExportReport event function
viewer.onBeginExportReport = function (args) {
switch (args.format) {
case "Html":
args.settings.zoom = 2; // Set HTML zoom factor to 200%
break;
}
}
// Assign the onReportDesign event function
viewer.onDesignReport = function (args) {
alert("Design button presed.");
}
// Create a new report instance
var report = new Stimulsoft.Report.StiReport();
// Load report from url
report.loadFile("../reports/SimpleList.mrt");
// Assign report to the viewer, the report will be built automatically after rendering the viewer
viewer.report = report;
// Show the report viewer in the 'content' element
viewer.renderHtml("content");
</script>In the screenshot below you can see the result of the sample code:
