From 6bf3891c764d42e01dae4e36c06216b969e1771d Mon Sep 17 00:00:00 2001 From: "y.suhodolov" Date: Fri, 23 Sep 2016 13:01:31 +0300 Subject: [PATCH 1/2] Ignored fields in total row fix --- src/Component/PageTotalsRow.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Component/PageTotalsRow.php b/src/Component/PageTotalsRow.php index 2c53dbc..d10588e 100644 --- a/src/Component/PageTotalsRow.php +++ b/src/Component/PageTotalsRow.php @@ -141,6 +141,10 @@ public function render() $valueFormatters[$column->getId()] = $prevFormatter = $column->getValueFormatter(); $column->setValueCalculator(null); $column->setValueFormatter(function ($value) use ($prevFormatter, $column) { + $operation = $this->getOperation($column->getId()); + if ($operation === static::OPERATION_IGNORE){ + return null; + } if ($prevFormatter) { $value = call_user_func($prevFormatter, $value); } From 707c6c002248258550ec996b7f3b9a9ad6a73d8d Mon Sep 17 00:00:00 2001 From: "v.stepanenko" Date: Mon, 26 Sep 2016 17:21:28 +0300 Subject: [PATCH 2/2] Refactoring, phpDoc --- src/Component/PageTotalsRow.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Component/PageTotalsRow.php b/src/Component/PageTotalsRow.php index d10588e..1b38676 100644 --- a/src/Component/PageTotalsRow.php +++ b/src/Component/PageTotalsRow.php @@ -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 */ @@ -133,7 +133,7 @@ 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) { @@ -142,13 +142,10 @@ public function render() $column->setValueCalculator(null); $column->setValueFormatter(function ($value) use ($prevFormatter, $column) { $operation = $this->getOperation($column->getId()); - if ($operation === static::OPERATION_IGNORE){ - return null; - } - if ($prevFormatter) { + 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; }