To work with report variables in the viewer you should use the support of special control panel. To add a parameter to the panel you should define the variable, which is requested from a user. When viewing a report in the viewer, this variable will be automatically added to the parameter panel. All types of report variables are supported (simple variables, date and time, range, lists, etc).

 

Control of variables on the parameter panel

To make some actions before assign parameters you should use the onInteraction event, which will be invoked when making interactive actions of the viewer. In arguments of the event the type of action and the collection of variables and their values, located on the parameter panel will be transferred. The type of action in this case will have the Variables value.

 

viewer.php

 

<?php

$viewer = new \Stimulsoft\Viewer\StiViewer();

$viewer->onInteraction = 'onInteraction';

$viewer->renderHtml();

?>

 

function onInteraction(args) {

if (args.action == "Variables") {

var variables = args.variables;

}

}

 

 

 

The collection of variables is the object, which contains all variables of the parameter panel and their values.

 

viewer.php

 

var variables = {

VariableString: "Text value",

VariableInt: 20

}

 

 

 

You can change values of variables, and the type of a new value should correspond to the type of the changed variable. You can find a detailed description of available argument values in the Viewer Events chapter.

 

Setting the parameter panel

If the work with variables in the viewer is not required, you can completely disable this feature. To do that you should use the showParametersButton property, which requires the setting of the false value.

 

viewer.php

 

<?php

$options = new \Stimulsoft\Viewer\StiViewerOptions();

$options->toolbar->showParametersButton = false;

?>

 

 

Information

 

When such configuration of the viewer is carried out, the parameter panel will not be displayed even if there are parameters in a displayed report.

 

 

 

Control of all report variables

If you need to control all report variables, you should use the onPrepareVariables event, which will be invoked before rendering a report.

 

viewer.php

 

<?php

$viewer = new \Stimulsoft\Viewer\StiViewer();

$viewer->onPrepareVariables = 'onPrepareVariables';

$viewer->renderHtml();

?>

 

function onPrepareVariables(args) {

var variables = args.variables;

}

 

 

 

You can control all variables both on the client-side and on the PHP server-side. You can find a detailed description in the Work with Report Variables in the engine section.