KoolReport's Forum

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

Drilldown undefined index #308

Open Michal opened this topic on on Jun 8, 2018 - 10 comments

Michal commented on Jun 8, 2018

Hello,

I'm working on reports with drilldown package. I'm trying to pass the example but i've got problem with: $drilldown = $this->params["@drilldown"] It returns me exception:

Notice: Undefined index: @drilldown

I'm working on symfony 4 framework. I think i must missunderstood something but can you please help me with that?

KoolReport commented on Jun 8, 2018

Hi Michal,

So you are using the CustomDrillDown, aren't you?

Regards,

KoolPHP Inc

Michal commented on Jun 11, 2018

I think so... I changed something but still have some problems with it. Below is my code if you could give me a little help with it i would be thankfull.

<?php
//Main.view.php
use \koolreport\drilldown\CustomDrillDown;

    CustomDrillDown::create(array(
            "name"=>"locationSale",
            "subReports"=>array("providers","realizations"),
    ))
?>
//Main.php
class Main extends \koolreport\KoolReport
{
    use \koolreport\core\SubReport;

    public function settings()
    {
        return array(
            "subReports"=>array(
                "providers"=>CountrySale::class,
                "realizations"=>StateSale::class
            )
        );
    }

    public function setup()
    {
    }
}
CountrySale.view.php
<?php
use \koolreport\widgets\google\BarChart;
$drilldown = $this->params["@drilldown"];

BarChart::create(array(
    "dataSource"=>$this->dataStore("providers"),
    "clientEvents"=>array(
        "itemSelect"=>"function(params){
        $drilldown.next({state:params.selectedRow[0]});
            
        }"
    ),
    "width"=>"100%",
    "columns"=>array(
        "NAME"=>array(
            "label"=>"name"
        ),
        "productsLack"=>array(
            "type"=>"number",
            "label"=>"Brak Towaru",
            "suffix"=>"%",
        )
    ),
    "colorScheme"=>array(
        "#de5307",
    ),
    "options"=>array(
        "chartArea"=>array(
            "height"=>"90%",
            "backgroundColor"=>"#fdfdfd"
        ),
        "backgroundColor"=>"#fdfdfd"
    ),
))
?>

When page loads. I've got first barchart. also in console i've got error: Uncaught ReferenceError: CustomDrillDown is not defined When i click on some bar there's: ncaught TypeError: Cannot read property 'next' of undefined [...] I don't know how to manage that. I thought i was going all same that is in the example but i have to miss something. Could you please give me little tip?

KoolReport commented on Jun 11, 2018

I got it, it is because resource for drill down is not loaded, you will need to output the client resource to public assets folder. Please follow this wiki post. Let me know if you need further assistance.

Michal commented on Jun 12, 2018

Yeah, i found this also but when i tried to load assets that way i've got error: Report's assets folder not existed I've made /assets directiory under public. The code looks like: `

public function settings()
{
    return array(
        "dataSources"=>array(
            "products"=>array(
                "connectionString"=>"mysql:host=db;dbname=**",
                "username"=>"**",
                "password"=>"**",
                "charset"=>"**"
            ),
        ),
        "assets"=>array(
            "path"=>"../assets",
            "url"=>"/assets"
        )
    );
}
I've tried different paths but i cannot handle it...
Michal commented on Jun 12, 2018

I've managed the path to be like:

            "assets"=>array(
                "path"=>"/var/www/html/public/assets",
                "url"=>"/assets"
            )

looks good but in console i've got error:

21:74 GET http://localhost:8081/var/www/html/vendor/koolphp/koolreport/koolreport/clients/jquery/jquery.min.js 404 (Not Found)

1:76 Uncaught ReferenceError: googleChartLoader is not defined
    at 1:76

I thought it should load the assets automaticaly? The files (also jquery) are copied to /assets directory

KoolReport commented on Jun 12, 2018

Could you please try the relative path from the report class to the assets folder.

Michal commented on Jun 13, 2018

Ok i've done that. However now i'm having problem with passing params to drilldown report. Can you please look at my code?

//Controller.php
 $report = new Main(array(
            "beginDate"=>$beginDate,
            "endDate"=>$endDate,
        ));
        $report->run();
        $view = $report->render("Main", true);
//Main.php
public function settings()
    {
        return array(
            "subReports"=>array(
                "providers"=>new CountrySale(array(
                    "beginDate"=>$this->params['beginDate'],
                    "endDate"=>$this->params['endDate'],
                )),
                "realizations"=>StateSale::class,
                "products"=>Realization::class
            ),
            "assets"=>array(
                "path"=>"/var/www/html/public/assets",
                "url"=>"/assets"
            )
        );
    }

And when I'm trying to reach those params:

//CountrySale.php
        $this->src('products')
            ->query("******")
            ->params(array(
                ":beginDate"=>$this->params['beginDate'],
                ":endDate"=>$this->params['endDate'],
            ))

They're not reachable. I've tried to dump($this->params) and die to check. The params looks good before query. Is there any other way to pass params to drilldown report and keep them for all levels?

KoolReport commented on Jun 13, 2018

Hi Michal,

This is not correct:

                "providers"=>new CountrySale(array(
                    "beginDate"=>$this->params['beginDate'],
                    "endDate"=>$this->params['endDate'],
                )),

it should be the class name as we did:

    "providers"=>CountrySale::class

In order to pass persisted params to all levels, you use scope, for example

            <?php
                \koolreport\drilldown\CustomDrillDown::create(array(
                    "name"=>"saleLocation",
                    "title"=>"Sale By Location",
                    "subReports"=>array("countrySale","citySale"),
                    "scope"=>array(
                        "beginDate"=>"2015-01-01",
                        "endDate"=>"2016-01-01",
                    )
                ));
            ?> 

Then all the level will have $this->params["beginDate"] and $this->params["endDate"]

Please let me know.

Michal commented on Jun 13, 2018

Yep I finally did it.

Thank you very much.

KoolReport commented on Jun 13, 2018

Awesome :)

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
None yet

None