LegacyDrillDown

Overview #

Note: LegacyDrillDown is the old DrillDown Widget. If you have used the old drilldown report, rename the class to LegacyDrillDown.

LegacyDrillDown is an widget that allows you to setup an drill-down report in fastest and easiest way. All you need to do are:

  1. Setup SQL Statement to withdraw data
  2. Setup multi-levels of drill-down.
  3. On each level of drill-down, choose chart type to visualize data

Example #

<?php 
LegacyDrillDown::create(array(
    "name"=>"saleReportByLocation",
    "title"=>"Sale By Location",
    //Define dataSource which is SQL statement to load all table
    "dataSource"=>(
        $this->src("mydata")->query("SELECT country, state, city, sale_amount FROM orders")
    ),
    //What we want to calculate
    "calculate"=>array(
        "sum"=>"sale_amount"
    ),
    "levels"=>array(
        //Level 1: Group all table by country, showing all countries with `sale_amount` by country.
        array(
            "groupBy"=>"country",
            "widget"=>array(ColumnChart::class,array(
                "columns"=>array("country","sale_amount")
            ))
            "title"=>"All countries",
        ),
        //Level 2: When user select a country, the widget shows `sale_amount` by state of that country
        array(
            "groupBy"=>"state",
            "widget"=>array(ColumnChart::class,array(
                "columns"=>array("state","sale_amount")
            )),
            "title"=>function($params)
            {
                return $params["country"];
            }
        ),
        //Level 3: When user continues to select a state, then widget will show  `sale_amount` by city of that state
        array(
            "groupBy"=>"city",
            "widget"=>array(Table::class,array(
                "columns"=>array("city","sale_amount")
            )),
            "title"=>function($params)
            {
                return $params["city"];
            }
        )
    )
));
?>

Properties #

nametypedefaultdescription
namestring*Required Name of the drill down report
dataSourcemixed*Required DataSource accepts data in form of DataStore, array, or even process.
dataStoremixedThis can be used alternatively to dataSource
calculatearray*Required Define what we want to summarize in form of "{method}"=>"{columnName}". The method supports "sum", "avg", "min", "max"
levelsarray* Required List of all levels for drill down report. See the level properties for more detail of settings on each level.
showLevelTitlebooltrueWhether title of each level is shown
btnBackmixedtrueBy 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")
cssmixedDefined css for the most important elements in the widgets, see the $css properties for more details.
panelStylestring"default"Set the panel style, accept value "default", "danger", "success", "info"
titlestringTitle that is showed on top of drill-down report.
scopearray/functionSet the group of parameters which will be kept persistent during the ajax post back of drill-down.
clientEventsarrayRegister client-event, see client-event for more details.

Css Properties #

nametypedefaultdescription
panelstringDefine css style for top panel
levelTitlestringDefine css style for section that holds titles of level
btnBackstringAdd css style for Back button
bodystringDefined css style for body

Examples

<?php
LegacyDrillDown::create(array(
    ...
    "css"=>array(
        "btnBack"=>"font-style:italic";
        "body"=>"height:300px;"
    )
));
?>

Level properties #

As we have seen from example on the top of page, levels property is an array of each level. Before are the settings of a level

nametypedefaultdescription
groupBystring*Required contain the column name which drill down will group by on each level
titlestring, functionSet the title information for each level, it accepts static string or a function to generate dynamic title for level. The function will receive a parameter as array containing all previous selection of users
widgetarrayContain the class name of widget that you want to use and its settings. You may use virtually all kind of widgets here. It could be Table or GoogleChart or any kinds of widgets available for KoolReport. Please see example of top for more details.

Client events #

LegacyDrillDown support following events:

namedescription
nextingFired when drill-down is preparing to go to next level. Return false to cancel action.
nextedFired when drill-down went to next level successfully.
backingFired when drill-down is going to go back to previous level. Return false to cancel action.
backedFired when drill-down went back to previous level
changedFired when drill-down changed level

Example

<?php
LegacyDrillDown::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.