There are two variants of report saving in the designer, which are available in the main menu and the main panel of the designer: Save and Save as. At the same time, each of these saving variants has its modes and settings.

 

 

Report saving on the JavaScript client-side

When clicking the Save button, a report template file is saved using browser features and you don't need any settings for it. If you need to save a report using your own methods, you should use the onSaveReport event. In arguments of the event, report file name and a report will be transferred. A report can be saved, for example, in a JSON string and transfer it to server-side using your own methods.

 

designer.php

 

<?php

$designer = new \Stimulsoft\Designer\StiDesigner();

$designer->onSaveReport = 'onSaveReport';

$designer->renderHtml();

?>

 

function onSaveReport(args) {

var fileName = args.fileName;

var report = args.report;

 

var jsonReport = args.report.saveToJsonString();

}

 

 

 

If the event is defined after the event completed, the designer continues to work without any additional actions and messages. If needed after saving a report you can display the dialog window with an error or a text message. To do it you should use the StiError.showError() function. It's up to you to define the need of display an error message.

 

designer.php

 

<?php

$designer = new \Stimulsoft\Designer\StiDesigner();

$designer->onSaveReport = 'onSaveReport';

$designer->renderHtml();

?>

 

function onSaveReport(args) {

var report = args.report;

 

// Error message

Stimulsoft.System.StiError.showError("An error occurred while saving the report.");

 

// Info message

Stimulsoft.System.StiError.showError("The report was saved successfully.", true, true);

}

 

 

 

When clicking the Save As button, the dialog window with report file name request will be displayed. After that report template file will be saved using browser features. If you need to save a report using your own methods, you should use the onSaveAsReport event. In arguments of the event report file name and a report will be transferred.

 

The work of this event is similar to the onSaveReport event work, apart from that after the event completed automatic saving report template on a computer using browser features. To stop this action, you should set the preventDefault property in the true value in arguments of the event and in this case, automatic saving will not be done.

 

designer.php

 

<?php

$designer = new \Stimulsoft\Designer\StiDesigner();

$designer->onSaveAsReport = 'onSaveAsReport';

$designer->renderHtml();

?>

 

function onSaveAsReport(args) {

args.preventDefault = true;

}

 

 

 

If needed, you can get access to an original report name or report name from the saving dialog by the following way.

 

designer.php

 

<?php

$designer = new \Stimulsoft\Designer\StiDesigner();

$designer->onSaveAsReport = 'onSaveAsReport';

$designer->renderHtml();

?>

 

function onSaveAsReport(args) {

// Report name from the designer save dialog

var reportName1 = args.fileName;

 

// Original report name from properties

var reportName2 = args.report.reportName;

}

 

 

 

You can find a detailed description of available values of arguments in the Designer Events section.

 

 

Report saving on the PHP server-side

To save a report on the PHP server-side, you should add the invoke of the event handler on the client-side, define the onSaveReport event of the same name on the server-side in the event handler file. You can find a detailed description of work of events in the PHP Events Handler chapter.

 

designer.php

 

<?php

$designer = new \Stimulsoft\Designer\StiDesigner();

$designer->onSaveAsReport = true;

$designer->renderHtml();

?>

 

 

handler.php

 

$handler->onSaveReport = function ($args) {

$fileName = $args->fileName;

$report = $args->report;

$reportJson = $args->reportJson;

 

return \Stimulsoft\StiResult::success();

};

 

 

 

In arguments of the event report file name and a report as an object and as a JSON string will be transferred. To save a report you can use standard PHP functions. For example, you need to save an edited report as a file in the specified directory.

 

handler.php

 

$handler->onSaveReport = function ($args) {

$fileName = $args->fileName;

$reportJson = $args->reportJson;

 

file_put_contents('reports/'.$fileName.'.mrt', $reportJson);

 

return \Stimulsoft\StiResult::success();

};

 

 

 

You can find a detailed description of available values of arguments in the Designer Events chapter.

 

Information

 

The work of the onSaveAsReport event is implemented in the same way on the PHP server-side. All arguments of the event have the same names and values.