Capture Empty Datasource in Viewer

Stimulsoft Reports.PHP discussion
Post Reply
servitux
Posts: 18
Joined: Thu Feb 29, 2024 3:29 pm

Capture Empty Datasource in Viewer

Post by servitux »

How can I capture event in which I can check if datasource is empty?

On Report.onBeginRender is not possible. isEmpty from dictionario.datasources.getByIndex(0) return true, but it has rows. There is any event on I can check this values?

Thansk. This is my html:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>{{$title}} - {{config('app.name')}}</title>

<?php
$js->renderHtml();
?>

<script type="text/javascript">
<?php
$handler->renderHtml();
?>

function onBeforeRender(event)
{
console.debug(event.report); <--- here event.report.dictionario.datasources.getByIndex(0).isEmpty return true

}

function onLoad() {
<?php
$viewer->renderHtml('viewerContent');
?>
}
</script>
</head>

<body onload="onLoad();">
<div id="viewerContent"></div>
</body>
</html>
Lech Kulikowski
Posts: 7033
Joined: Tue Mar 20, 2018 5:34 am

Re: Capture Empty Datasource in Viewer

Post by Lech Kulikowski »

Hello,

What data sources are you use in your report - is it file XML, JSON or SQL sources?

Thank you.
servitux
Posts: 18
Joined: Thu Feb 29, 2024 3:29 pm

Re: Capture Empty Datasource in Viewer

Post by servitux »

Hi.

SQL Source. MySQL indeed
Lech Kulikowski
Posts: 7033
Joined: Tue Mar 20, 2018 5:34 am

Re: Capture Empty Datasource in Viewer

Post by Lech Kulikowski »

Hello,

Please try to check the onEndProcessData event:
https://www.stimulsoft.com/en/documenta ... l_data.htm

Thank you.
servitux
Posts: 18
Joined: Thu Feb 29, 2024 3:29 pm

Re: Capture Empty Datasource in Viewer

Post by servitux »

Hi, thanks for reply

But, where? in HTML / Javascript I can't capture onEndProcessData. How can i do it? I try to update my php StiReport object with $this->onEndProcessData = true, at the same way with onBeginRender event, the event onEndProcessData never fires.

In addition, the viewer, after render, fires an alert with this message: "Unknown event [EndProcessData]"

My HTML:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>{{$title}} - {{config('app.name')}}</title>

<?php
$js->renderHtml();
?>

<script type="text/javascript">
<?php
$handler->renderHtml();
?>

function onBeforeRender(event)
{
var variable = event.report.dictionary.variables.getByName('CULTURE')
if (variable) variable.value = "{{$report->culture}}";
}

function onEndProcessData(event)
{
console.debug(event.report); <--------------------- this never fires
}

function onLoad() {
<?php
$viewer->renderHtml('viewerContent');
?>
}
</script>
</head>

<body onload="onLoad();">
<div id="viewerContent"></div>
</body>
</html>
Lech Kulikowski
Posts: 7033
Joined: Tue Mar 20, 2018 5:34 am

Re: Capture Empty Datasource in Viewer

Post by Lech Kulikowski »

Hello,

Please check the following samples:
https://github.com/stimulsoft/Samples-Reports.PHP

Thank you.
servitux
Posts: 18
Joined: Thu Feb 29, 2024 3:29 pm

Re: Capture Empty Datasource in Viewer

Post by servitux »

Hi. Thanks for reply.

In my case, my version of library was 2023.4. I've updated to 2025.1 and now, with server side rendering and new report/viewer classes all is more easy.

I'm going to close this thread, and open another with a server-side rendering and exporting.

Bye.
Lech Kulikowski
Posts: 7033
Joined: Tue Mar 20, 2018 5:34 am

Re: Capture Empty Datasource in Viewer

Post by Lech Kulikowski »

Hello,

You are welcome.
Post Reply