KoolReport's Forum

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

Drilldown Using Array datasource #1042

Open Charles Chang opened this topic on on Aug 15, 2019 - 3 comments

Charles Chang commented on Aug 15, 2019

Hi,

Can you show me a simple example of a Drilldown using Array as datasource ? not sql or query..

for example

DrillDown::create(array(
        "name"=>"saleDrillDown",
        "title"=>"Sale Report",
        "levels"=>array(
            array(
                "title"=>"All Years",
                "content"=>function($params,$scope)
                {
                    ColumnChart::create(array(
                        "dataSource"=>(
                   <strong>$this->src("automaker")->[Array] </strong>
                        ),

Thanks!

KoolReport commented on Aug 15, 2019

You can just insert the array "dataSource"=>$this->src("automaker") . Make sure that the automaker there is the array datasource. More example of setting up array datasource is here.

Even you can set array directly like this:

    "dataSource"=>array(
        array("name"=>"Peter","salary"=>2000),
        array("name"=>"David","salary"=>5000),
    ),
Charles Chang commented on Aug 16, 2019

Thanks for your reply.. it works when you directly input the array in the dataSource,. but when coming from a variable, it's not working, please help

 $testArr = array(  ['name' => 'TEST1', 'qty'=> 23],  ['name' => 'TEST2', 'qty'=> 223]
                                   );

                DrillDown::create(array(
                    "name"=>"drugClassDrillDown",
                    "title"=>"Psychotropic Report",
                    "levels"=>array(
                        array(
                            "title"=>"Psychotropic Drug by Class",
                            "content"=>function($params,$scope)
                            {
                                ColumnChart::create(array(
                                    "dataSource"=>$testArr,
                                    "columns"=>array(
                                        "name",
                                        "qty"=>array("label"=>"Count","type"=>"number"),
                                    ),
                                    "clientEvents"=>array(
                                        "itemSelect"=>"function(params){
                                drugClassDrillDown.next({class:params.selectedRow[0]});
                            }",
                                    )
                                ));
                            }
                        ),
                    ),
                ));22
KoolReport commented on Aug 17, 2019

Hi, the $testArr is outside scope of function, thats why function could not get it. You can try:

"content"=>function($params,$scope) use ($testArr) {

}

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

Laravel