KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Report Selector #3221

Closed Eugene opened this topic on on Jan 2 - 12 comments

Eugene commented on Jan 2

Hi KoolReport team.

What is the best way to create a report selector?

I mean a 'Select' with the list of reports and depending on the selection - the corresponding report is rendered below. It could be different reports (different data sources and logic) so it is not only the question of the parameters

I think it is possible to implement with Subreports, but I need your advice.

KoolReport commented on Jan 4

Yes, SubReport should be the way. No doubt about it.

Eugene commented on Jan 4

I think I did something wrong.... what could be the reason for the error in the console Failed to load resource: the server responded with a status of 404 (Could not find [exportselecting] sub report) It happens after I change the select value... but the name of the report in the select input in SelectExport.view.php is correct with the corresponding line in the settings function in SelectExport.php

Eugene commented on Jan 4

I am not sure but I think it is due to my attempt to use a subreport inside another subreport... but I don't know how else I can realize my idea.. I cannot directly use your Subreport example because the report output is different depending on the selected report - I need that the final report can be updated from the 'selecting' subreport

My files you can find here

Eugene commented on Jan 5

It looks like I found the solution and it works now. But what I don't so like it is that all my subreports are always executed in the main view file this way even the reports that are not selected:

<div class='row'>
    <?php $this->subReport("salesexport"); ?>
</div>

<div class='row'>
    <?php $this->subReport('expensesexport'); ?>
</div>

I am not sure if is it good from the productivity point of view if some of these reports are pretty heavy... but I was not able to find a way to execute only the report that is selected.

KoolReport commented on Jan 5

You can base on the selection of report to generate accordingly subreport with default is the ExpenseExport if nothing is selected:

<?php
    switch($exportMode)
    {
        case "Sales":
            $this->subReport("salesexport");
            break;
        case "Expense":
        default:
            $this->subReport("expeseexport");
    }
?>
Eugene commented on Jan 5

Hm, I don't think it works This code is a part of the analog of your CustomerOrders.view.php

 $this->subReport("salesexport");

As I understand the selection that was made in the subreport like in yours CustomerSelecting is not available at the moment of the execution of CustomerOrders.view.php

Eugene commented on Jan 5

I tried to check

if (isset($this->params['exportMode'])) {
        echo $this->params['exportMode'];
    } else {echo 'NOT SET';}
    $this->subReport("salesexport"); ?>

It returns NOT SET and only once before any selection was made

Eugene commented on Jan 6

any idea how can i control it?

KoolReport commented on Jan 7

That makes senses as in the first load "exportMode" is not available yet, you can set a default value for exportMode parameters or you can just load the default report.

Eugene commented on Jan 14

I think you might be wrong... This part of the code in the main view files is executed only once and not re-executed when the subreport is updated. So the problem is not in the availability of "exportMode".

How can I update the main report?

Eugene commented on Jan 17

up :-(

KoolReport commented on Jan 18

Sorry for my late reply. I think there is a simpler solution using $.ajax() to update a div. You render the main report with a Select and a blank div (with an id). On the event of selection of Select, you send request ajax to another file call reportselector.php with an parameter "reportName", on that file base on the reportName, you render the corresponding report. At client-side, upon receiving the html, you just use the $.html() to insert html into the div. It will works.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

None