Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines
Hi Elcid,
Please download our latest KoolReport package and try the following code:
use \koolreport\core\Utility as Util;
...
->pipe(new Sort(array(
'sales' => 'desc',
)))
->pipe(new Map([
'{aggregate}' => function($row, $meta, $index, $data) {
if ($index >= 5) {
$sum = Util::init($data, 'others', []);
foreach ($row as $c => $v) {
Util::init($sum, $c, 0);
$sum[$c] = is_numeric($v) ? $sum[$c] + $v : 'Others';
}
$data['others'] = $sum;
return $data;
}
},
'{value}' => function($row, $meta, $index) {
if ($index < 5)
return $row;
},
'{end}' => function($count, $data) {
return $data;
},
]))
->pipe($this->dataStore('myDatastore'));
Please remember to change the "sales" field to your data column. Let us know if you have any problem. Thanks!
Let KoolReport help you to make great reports. It's free & open-source released under MIT license.
Download KoolReport View demo