KoolReport's Forum

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

CustomDrillDown can't go to the next level #389

Open Anita opened this topic on on Jul 24, 2018 - 4 comments

Anita commented on Jul 24, 2018

Dear Support, I have been working with CustomDrillDown. I can display the first level of results but I can't go to the next one. There's no active fields (last_name) that I could click on. Here's my code:

//MaClasse_all.php - first level
<?php
require_once "../koolreport/autoload.php";
class MaClasse_all extends \koolreport\KoolReport
{
     function settings()
    {
        include "param_connexion_database.php";
        return  $database_connection;
    }

    function setup()
    {
        $this->src("database")
        ->query('SELECT p.last_name, p.first_name, count(i.start_date)
                    from 
                    intervention i
                    group by 
                    p.last_name, p.first_name limit 30')
        ->pipe($this->dataStore("result_view_all"));

//MaClasse_all.view.php
<?php 
   use \koolreport\widgets\koolphp\Table;
   $drilldown = $this->params["@drilldown"]
?>
<level-title>Tous les collaborateurs</level-title>

<?php
Table::create(array(
    "dataSource"=>$this->dataStore("result_view_all"),
    "clientEvents"=>array(
        "itemSelect"=>"function(params){
            $drilldown.next({last_name:params.selectedRow[0]});
        }"
    )
))
?>

//MaClasse_user - second level
<?php
require_once "../koolreport/autoload.php";
class MaClasse_user extends \koolreport\KoolReport
{
      function settings()
    {
        include "param_connexion_database.php";
        return  $database_connection;
    }

     function setup()
    {
        $this->src("database")
        ->query('SELECT p.last_name, p.first_name,i.start_date 
                    from 
                    intervention i
                    where 
                    p.last_name like :last_name
        ->params(array(
            ":last_name"=>$this->params["last_name"]
        ))
        ->pipe($this->dataStore("result_view_user"));
    }
}
?>
//MaClasse_user.view
<?php 
    use \koolreport\widgets\koolphp\Table;
    $drilldown = $this->params["@drilldown"]
?>
<level-title>Présences de <?php echo $this->params["last_name"]; ?></level-title>
<?php
Table::create(array(
    "dataSource"=>$this->dataStore("result_view_user"),
))
?>
//MainReport
<?php
require_once "../koolreport/autoload.php";

class MainReport extends \koolreport\KoolReport
{
    use \koolreport\clients\Bootstrap;
    use \koolreport\core\SubReport;
     function settings()
    {
        return array(
            "subReports"=>array(
                "all_users"=>MaClasse_all::class,
                "one_user"=>MaClasse_user::class
            )
        );
    }
    function setup()
    {
    }
}
?>
//MainReport.view
<?php 
    //MainReport.view.php
    use \koolreport\drilldown\CustomDrillDown;
    require_once "MaClasse_all.php";
    require_once "MaClasse_user.php";
?>

<html>
    <head>
        <title> Présences </title>
    </head>
    <body>
        <?php
        CustomDrillDown::create(array(
            "name"=>"main_report",
            "title"=>"Presences des collaborateurs mainreportview",
            "subReports"=>array("all_users","one_user"),
        	))
        ?>
        ```
    </body>
</html>

//index.php
<?php
    require_once "MainReport.php";

    $report = new MainReport();

 	$report->run()->render();
?>


I can't see what is wrong. Thank you in advance for your help.

KoolReport commented on Jul 25, 2018

You need to do this on the MaClasse_user.view.php:

Table::create(array(
    "clientEvents"=>array(
        "rowClick"=>"function(params){
            $drilldown.next({last_name:params.rowData[0]});
        }            
        "
    )
));

The key here is that Table does not have itemSelect but rowClick. and the row data is get from rowData, you can access the last_name either by params.rowData[0] (because last_name is the first column) or through params.rowData['last_name'].

Hope that helps.

Anita commented on Jul 25, 2018

Thank you for the quick reply. I have replaced the code itemSelect.. by rowClick.. in MaClasse_all.view (this code should be in the first level view file, right ? (Putting it in MaClasse_user.view.php - the second level view file - didn't change anything).

So now I can click on rows but I get no results, only a truncated message error as in the print screen :

I can go back to the first level by clicking on the button "back" or on the first level title ("Tous les collaborateurs"), but I get no results for the second level.

KoolReport commented on Jul 25, 2018

Please see what the error message says. I think there is issue with second level. Please test this level first, you can do this to test:

$report = new MaClasse_user(array(
    "last_name"=>"some name"
));
$report->run()->render();

Let see if the report return correctly table as you expected. One thing I discover when looking at your code, you should do like this:

->params(array(
    ":last_name"=>"%".$this->params["last_name"]."%"
))
...
Anita commented on Jul 26, 2018

OK, I finally found what was causing the error : in the controlller (index.php) 'require_once "MaClasse_user.php";' was missing.

<?php
    require_once "MainReport.php";
    require_once "MaClasse_user.php";

    $report = new MainReport();

     $report->run()->render();
?>

Thanks for all the hints!

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

DrillDown