Skip to content

Commit

Permalink
Merge pull request #23 from view-components/ignored_columns_total_fix
Browse files Browse the repository at this point in the history
Ignored fields in total row fix
  • Loading branch information
Nayjest authored Sep 26, 2016
2 parents 7e59a65 + 707c6c0 commit 918d55e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Component/PageTotalsRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PageTotalsRow implements PartInterface, ViewComponentInterface
];

/**
* Keys are column id's and values are operations (see PageTotalsRow::OPERATION_* constants).
* Keys are column id's and values are operations (PageTotalsRow::OPERATION_* constants or closures).
*
* @var string[]|array
*/
Expand Down Expand Up @@ -133,18 +133,19 @@ public function render()
$lastRow = $grid->getCurrentRow();
$grid->setCurrentRow($this->totalData);

// modify columns
// modify columns, prepare it for rendering totals row
$valueCalculators = [];
$valueFormatters = [];
foreach ($grid->getColumns() as $column) {
$valueCalculators[$column->getId()] = $column->getValueCalculator();
$valueFormatters[$column->getId()] = $prevFormatter = $column->getValueFormatter();
$column->setValueCalculator(null);
$column->setValueFormatter(function ($value) use ($prevFormatter, $column) {
if ($prevFormatter) {
$operation = $this->getOperation($column->getId());
if ($prevFormatter && !($operation === static::OPERATION_IGNORE || $operation instanceof Closure)) {
$value = call_user_func($prevFormatter, $value);
}
$operation = $this->getOperation($column->getId());
// Add value prefix if specified for operation
if ($value !== null && is_string($operation) && array_key_exists($operation, $this->valuePrefixes)) {
$value = $this->valuePrefixes[$operation] . ' ' . $value;
}
Expand Down

0 comments on commit 918d55e

Please sign in to comment.