CustomDrillDown
Overview #
CustomDrillDown
extends the capability to the max. It does not limit the number of charts in a level, you can show any custom content inside a level of drilldown. Due to flexibility, CustomDrillDown
is a little more complicated to handle than normal drilldown above. To summarize the comparison between CustomDrillDown
and DrillDown
- CustomDrillDown is faster than DrillDown since CustomDrillDown use the SubReport technology.
- When callback, only subreport of CustomDrillDown runs so it is more efficient while DrillDown will run the whole main report so it is less efficient.
- In CustomDrillDown, you need to setup subreport and connecting them with parameters while in DrillDown, you do not need to, we handle all for you.
- In sum, DrillDown vs CustomDrillDown is the trade-off between the convenience and the powerfulness, the easiness and the complexity.
Step By Step Tutorial #
Step 1: Create CountrySale report #
The CountrySale report is created in the same way you create a single report. In this CountrySale report, we summarize sale by country and display all countries. When user select a country, it called DrillDown next() function to pass the selection parameters to the next level.
<?php
class CountrySale extends \koolreport\KoolReport
{
protected function settings()
{
return array(
"dataSources"=>array(
"mydatabase"=>array(
"connectionString"=>"mysql:host=localhost;dbname=mydata",
"username"=>"root",
"password"=>"",
"charset"=>"utf8"
)
)
);
}
protected function setup()
{
$this->src("mydatabase")
->query("SELECT country, sum(amount) AS sale_amount FROM orders GROUP BY country")
->pipe($this-dataStore("sale_by_country"));
}
}
<?php
//CountrySale.view.php
use \koolreport\widgets\google\ColumnChart;
$drilldown = $this->params["@drilldown"]
?>
<level-title>All Countries</level-title>
<?php
ColumnChart::create(array(
"dataSource"=>$this->dataStore("sale_by_country"),
"clientEvents"=>array(
"itemSelect"=>"function(params){
$drilldown.next({country:params.selectedRow[0]});
}"
)
))
?>
Step 2: Create StateSale report #
The StateSale report is created in the same way that you create a single report. StateSale report will receive a parameter called "country" which is the selected country from user. It will summarize the sale_amount by state in that country.
<?php
class StateSale extends \koolreport\KoolReport
{
protected function settings()
{
return array(
"dataSources"=>array(
"mydatabase"=>array(
"connectionString"=>"mysql:host=localhost;dbname=mydata",
"username"=>"root",
"password"=>"",
"charset"=>"utf8"
)
)
);
}
protected function setup()
{
$this->src("mydatabase")
->query("
SELECT
state, sum(amount) AS sale_amount
FROM orders
WHERE
country=:country
GROUP BY state
")
->params(array(
":country"=>$this->params["country"]
))
->pipe($this-dataStore("sale_by_state"));
}
}
<?php
//CountrySale.view.php
use \koolreport\widgets\google\ColumnChart;
$drilldown = $this->params["@drilldown"]
?>
<level-title>States of <?php echo $this->params["country"]; ?></level-title>
<?php
ColumnChart::create(array(
"dataSource"=>$this->dataStore("sale_by_state"),
))
?>
Step 3: Create MainReport #
The MainReport defines the CountrySale and StateSale as subreports and create CustomDrillDown at the view.
<?php
class MainReport extends \koolreport\KoolReport
{
use \koolreport\clients\Bootstrap;
protected function settings()
{
return array(
"subReports"=>array(
"countrysale"=>CountrySale::class,
"statesale"=>StateSale::class
)
);
}
protected function setup()
{
}
}
<?php
//MainReport.view.php
use \koolreport\drilldown\CustomDrillDown;
?>
<html>
<head>
<title> Sale By Location</title>
</head>
<body>
<?php
CustomDrillDown::create(array(
"name"=>"locationSale"
"title"=>"Sale By Location",
"subReports"=>array("countrysale","statesale"),
))
?>
```
</body>
</html>
As result of above settings, now you have a drilldown report that will show all countries with the sales achived in each country. When user selects a particular country, the drilldown will show the sale_amount by each states in that country. Awesome, is it?
Each levels of drill-down report is handled by a sub report which virtually you can customize the interface in the way you want. All you need to do is to call next() function of drill down, sending all selected values then wait for drilldown to move to next level.
Properties #
name | type | default | description |
---|---|---|---|
name | string | *Required Name of drill down | |
title | string | Title that is showed on top of drill-down report. | |
subReports | array | *Required List of sub report name in level order | |
showLevelTitle | bool | true | Whether title of each level is shown |
btnBack | mixed | true | By default, the button Back will shown, give it value false you will off the Back button. This property can receive array() to customize cssClass and text of button "btnBack"=>array("text"=>"Go Back","class"=>"btn btn-default btn-warning") |
css | mixed | Defined css for the most important elements in the widgets, see the $css properties for more details. | |
panelStyle | string | "default" | Set the panel style, accept value "default" , "danger" , "success" , "info" |
scope | array/function | Any params you want to included for sub report in form of associated array. You also may use a function and return associate array | |
clientEvents | array | Register client-event, please see the Client Events for more details |
Css Properties #
name | type | default | description |
---|---|---|---|
panel | string | Define css style for top panel | |
levelTitle | string | Define css style for section that holds titles of level | |
btnBack | string | Add css style for Back button | |
body | string | Defined css style for body |
Client events #
CustomDrillDown
support following events:
name | description |
---|---|
nexting | Fired when CustomDrillDown is preparing to go to next level. Return false to cancel action. |
nexted | Fired when CustomDrillDown went to next level successfully. |
backing | Fired when CustomDrillDown is going to go back to previous level. Return false to cancel action. |
backed | Fired when CustomDrillDown went back to previous level |
changed | Fired when CustomDrillDown changed level |
Example
<?php
CustomDrillDown::create(array(
...
"clientEvents"=>array(
"nexting"=>"function(params){
return false;//Cancel action
}",
"nexted"=>"function(params){
console.log('Nexted to'+params.level);
}",
);
));
?>
Get started with KoolReport
KoolReport will help you to construct good php data report by gathering your data from multiple sources, transforming them into valuable insights, and finally visualizing them in stunning charts and graphs.