Sometime you may want to simplify your data flow by taking only some of columns to continue in datapipe. You can do so with OnlyColumn process. This process will act like a filter which only let some specified columns passing through. Other columns will be discarded.
Sample code
->pipe(new OnlyColumn(array(
"age", "income"
)))
<?php
require_once "MyReport.php";
$report = new MyReport;
$report->run()->render();
<?php
//Step 1: Load KoolReport
require_once "../../../load.koolreport.php";
use \koolreport\processes\OnlyColumn;
//Step 2: Creating Report class
class MyReport extends \koolreport\KoolReport
{
protected function settings()
{
return array(
"dataSources"=>array(
"data"=>array(
"class"=>'\koolreport\datasources\ArrayDataSource',
"dataFormat"=>"table",
"data"=>array(
array("name","income","age"),
array("John",50000,25),
array("Marry",60000,30),
array("Peter",100000,45),
array("Donald",80000,40),
)
)
)
);
}
protected function setup()
{
//Prepare data
$this->src("data")
->pipe($this->dataStore("origin"));
//Pipe through process to get result
$this->src("data")
->pipe(new OnlyColumn(array(
"age", "income"
)))
->pipe($this->dataStore("result"));
}
}
<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\LineChart;
?>
<div class="report-content">
<div class="text-center">
<h1>OnlyColumn Process</h1>
<p class="lead">Keep selected columns and discard the rest</p>
</div>
<?php
Table::create(array(
"dataSource"=>$this->dataStore("origin"),
"cssClass"=>array(
"table"=>"table-bordered table-striped table-hover"
)
));
?>
<i class="fa fa-arrow-down" style="font-size:24px;"></i>
<pre style="font-weight:bold"><code>
->pipe(new OnlyColumn(array(
"age", "income"
)))
</code></pre>
<i class="fa fa-arrow-down" style="font-size:24px;"></i>
<div style="margin-top:20px;">
<?php
Table::create(array(
"dataSource"=>$this->dataStore("result"),
"cssClass"=>array(
"table"=>"table-bordered table-striped table-hover"
)
));
?>
</div>
</div>