Closed listeroabsoluto closed 12 years ago
You can create your own DQL function to perfom these calculations.
OR
Define charges.ammount:sum and partialDischarges.ammount:sum with source=true and visible=false, create a new column and use the maipulateRow feature:
<?php
$source->manipulateRow(function ($row) {
return $row->setField('diff', $row->getField('charges.ammount:sum') - $row->getField('partialDischarges.ammount:sum'));
});
$grid->addColumn(new BlankColumn(['id' => 'diff', 'title' => 'diff','size' => '30']))
OR
Don't define charges.ammount:sum and partialDischarges.ammount:sum, groupBy on the good column, create a new column 'diff' and use the maipulateQuery feature:
Exemple:
<?php
$tableAlias = $source::TABLE_ALIAS;
$source->manipulateQuery(function ($query) use ($tableAlias) {
$query->addSelect('SUM((11 - IfNull('.$tableAlias.'.rank, 11))) as points');
});
$grid->addColumn(new BlankColumn(['id' => 'points', 'title' => 'points','size' => '30']))
It's good for you ?
I think, this approach es excellent. I have implement your solution in my codes, is very flexible.
In any case, this logic must be in controllers? This is a presentation layer scope or a data object (calculated field) logic?
This logic must be in controllers?
Yes
This is a presentation layer scope or a data object (calculated field) logic?
Presentation
I need this feature.
Item.count Item.price Item.total <--- calculated
Item.total is not persisted, must be calculate by performing a operation between Item.count * Item.price
Is posible do this with the current versión, showing a new column TOTAL, writing a getter in Item entity, but what about aggregated fields?
This is my real problem:
I need a new Grid\Column with this diference: charges.ammount:sum - partialDischarges.ammount:sum
Any ideas?
Thanks.