The footer of KoolPHP Table can show the summarized number like sum, average, count etc.
To turn on this feature you set
"showFooter"=>true
To show aggregation value for a column you set "footer" property to the method you want to calculate for example "sum"
,"count"
, "avg"
, "min"
or "max"
"footer"=>"sum"
To customize the footer text, you use "footerText"
:
"footerText" =>"<b>Total</b>: @value"
<?php
require_once "MyReport.php";
$report = new MyReport;
$report->run()->render();
<?php
//Step 1: Load KoolReport
require_once "../../../load.koolreport.php";
//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","age","income"),
array("John",26,50000),
array("Marry",29,60000),
array("Peter",34,100000),
array("Donald",28,80000),
)
)
)
);
}
protected function setup()
{
$this->src("data")
->pipe($this->dataStore("data"));
}
}
<?php
use \koolreport\widgets\koolphp\Table;
?>
<div class="report-content">
<div class="text-center">
<h1>Footer Settings</h1>
<p class="lead">Show footer and calculated aggregation</p>
</div>
<?php
Table::create(array(
"dataSource"=>$this->dataStore('data'),
"showFooter"=>true,
"columns"=>array(
"name",
"age",
"income"=>array(
"cssStyle"=>"text-align:right",
"prefix"=>"$",
"footer"=>"sum",
"footerText"=>"<b>Total:</b> @value"
)
),
"cssClass"=>array(
"table"=>"table-bordered table-striped table-hover"
)
));
?>
<div class="text-center">
<h4>On Top</h4>
<p class="lead">Show aggregated footer on top</p>
</div>
<?php
Table::create(array(
"dataSource"=>$this->dataStore('data'),
"showFooter"=>"top",
"columns"=>array(
"name",
"age",
"income"=>array(
"cssStyle"=>"text-align:right",
"prefix"=>"$",
"footer"=>"sum",
"footerText"=>"<b>Total:</b> @value"
)
),
"cssClass"=>array(
"table"=>"table-bordered table-striped table-hover"
)
));
?>
</div>