pattern to open viewer in js

Stimulsoft Reports.PHP discussion
suyonob
Posts: 19
Joined: Mon Feb 18, 2013 6:42 am

pattern to open viewer in js

Post by suyonob »

hello, would you describe how to show report in viewer in js.
in faq described only flash.
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: pattern to open viewer in js

Post by HighAley »

Hello.

You could find a sample in c:\Users\Public\Documents\Stimulsoft Samples 2015.3\Stimulsoft Reports.PHP\JS\ folder.
Please, look at the viewer.php file.

Thank you.
suyonob
Posts: 19
Joined: Mon Feb 18, 2013 6:42 am

Re: pattern to open viewer in js

Post by suyonob »

thank you.
in flash. to open report in viewer have address :

http://localhost/stimulsoft/index.php?s ... Report.mrt

how to accomplish this way when using js ?
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: pattern to open viewer in js

Post by HighAley »

Hello.

Sorry, maybe we don't understand your question.
Could you describer your issue more detailed?

Thank you.
suyonob
Posts: 19
Joined: Mon Feb 18, 2013 6:42 am

Re: pattern to open viewer in js

Post by suyonob »

i mean i want to know how to open report in viewer using js like in flash.
below are attachment that i captured from faq of stimulsoft php.

thank you
Attachments
Screenshot_2015-12-08-04-38-11.png
Screenshot_2015-12-08-04-38-11.png (99.96 KiB) Viewed 9610 times
Screenshot_2015-12-08-04-38-29.png
Screenshot_2015-12-08-04-38-29.png (108.42 KiB) Viewed 9610 times
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

Re: pattern to open viewer in js

Post by Vladimir »

Hello,

JS PHP product is more universal in use than Flash, so the usage scenarios are different. You can use the following code to work with the report using JavaScript object StiReport:

index.php

Code: Select all

	var report = new Stimulsoft.Report.StiReport();
	report.loadFile("getreport.php?id=<?php echo $report_id; ?>");
getreport.php

Code: Select all

<?php
	$report_id = $_GET["id"];
	$file = "reports/$report_id.mrt";
	
	if (file_exists($file)) {
		header('Content-Description: File Transfer');
		header('Content-Type: application/json');
		header('Content-Disposition: attachment; filename="'.basename($file).'"');
		header('Content-Length: '.filesize($file));
		readfile($file);
		exit;
	}
?>
Thank you.
suyonob
Posts: 19
Joined: Mon Feb 18, 2013 6:42 am

Re: pattern to open viewer in js

Post by suyonob »

thank you.
yes i got using js. and what about using parameter. what should i do ?
Vladimir
Posts: 1462
Joined: Fri Apr 13, 2007 4:05 am
Location: Earth

Re: pattern to open viewer in js

Post by Vladimir »

Hello,

You can assign parameters from URL to the report as follows:

Code: Select all

function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,
        function (m, key, value) {
            vars[key] = value;
    });
    return vars;
}

var vars = getUrlVars();
report.dictionary.variables.list.forEach(function(item, i, arr) {
    if (typeof vars[item.name] != "undefined") item.valueObject = vars[item.name];
});

viewer.report = report;
Also, you can optionally add code to validate the values of variables in accordance with your requirements.

Thank you.
suyonob
Posts: 19
Joined: Mon Feb 18, 2013 6:42 am

Re: pattern to open viewer in js

Post by suyonob »

thank you.
would you like to explain to us line by line how to add/insert parameter into your code above ?

and i have try to write sql from js designer but when i addedd parameter, there can not saved.
thank you very much
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

Re: pattern to open viewer in js

Post by HighAley »

Hello.

This code takes all parameters from URL and set values of variables if it exists in the report with the same name.

Could you describe your issue more detailed? Who do you add the parameter?

Thank you.
Post Reply