Step 1:
<?php $this->widget('bootstrap.widgets.TbGridView', array( 'id' => 'my-grid', 'dataProvider' => $model->search(), 'template' => '{items}', 'columns' => array( array( 'header' =>'Amount 1', 'name' => 'amount_1', 'footer'=>'Total (Amount 1 + Amount 2)', ), array( 'header' => 'Amount 2', 'name' => 'amount_2', 'footer' => $model->getTotal($model->search()->getData(), 'amount_1','amount_2'), ), ), )); ?>
Step 2:
<?php public function getTotal($records, $data1, $data2) { $total = 0; foreach ($records as $record) { $total += $record->$data1 + $record->$data2; } return number_format($total, 2); } ?>
No comments:
Post a Comment