Viewer Events

This example shows how to use the report viewer events. Some viewer actions have events to which you can subscribe. For example, print action, end of the export, design report:

// 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.onGetReportData = function (event) {
var ds = new Stimulsoft.System.Data.DataSet("Demo");
ds.readJsonFile("../reports/Demo.json");
event.report.regData("Demo", "Demo", ds);
}

// Assign the onPrintReport event function
viewer.onPrintReport = function (event) {

}

// Assign the onReportExport event function
viewer.onEndExportReport = function (event) {
switch (event.format) {
case Stimulsoft.Report.StiExportFormat.Html:
event.settings.zoom = 2; // Set HTML zoom factor to 200%
break;
}
}

// Assign the onReportDesign event function
viewer.onDesignReport = function (event) {
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");


In the screenshot below you can see the result of the sample code.

Viewer Events