ColumnsSort is a process to sort your data pipe's columns by their names or labels. The sort direct could be ascending, descending, or custom comparative function order.
Sample code
->pipe(new ColumnsSort(array(
"{name}" => "asc",
// "{label}" => "desc",
// "{name}" => function ($a, $b) { return $a < $b ? -1 : 1; },
// "{label}" => function ($a, $b) { return $a < $b ? 1 : -1; },
)))
<?php
require_once "MyReport.php";
$report = new MyReport;
$report->run()->render();
<?php
//Step 1: Load KoolReport
require_once "../../../load.koolreport.php";
use \koolreport\processes\ColumnsSort;
//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"),
array("John",50000),
array("Marry",60000),
array("Peter",100000),
array("Donald",80000),
)
)
)
);
}
protected function setup()
{
//Prepare data
$this->src("data")
->pipe($this->dataStore("origin"));
//Pipe through process to get result
$this->src("data")
->pipe(new ColumnsSort(array(
"{name}" => "asc",
// "{label}" => "desc",
// "{name}" => function ($a, $b) { return $a < $b ? -1 : 1; },
// "{label}" => function ($a, $b) { return $a < $b ? 1 : -1; },
)))
->pipe($this->dataStore("result"));
}
}
<?php
use \koolreport\widgets\koolphp\Table;
use \koolreport\widgets\google\LineChart;
?>
<div class="report-content">
<div class="text-center">
<h1>ColumnsSort Process</h1>
<p class="lead">Sort columns by name or label</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 ColumnsSort(array(
"{name}" => "asc",
// "{label}" => "desc",
// "{name}" => function ($a, $b) { return $a < $b ? -1 : 1; },
// "{label}" => function ($a, $b) { return $a < $b ? 1 : -1; },
)))
</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>