Skip to content

Commit 918d55e

Browse files
authored
Merge pull request #23 from view-components/ignored_columns_total_fix
Ignored fields in total row fix
2 parents 7e59a65 + 707c6c0 commit 918d55e

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Component/PageTotalsRow.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class PageTotalsRow implements PartInterface, ViewComponentInterface
3939
];
4040

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

136-
// modify columns
136+
// modify columns, prepare it for rendering totals row
137137
$valueCalculators = [];
138138
$valueFormatters = [];
139139
foreach ($grid->getColumns() as $column) {
140140
$valueCalculators[$column->getId()] = $column->getValueCalculator();
141141
$valueFormatters[$column->getId()] = $prevFormatter = $column->getValueFormatter();
142142
$column->setValueCalculator(null);
143143
$column->setValueFormatter(function ($value) use ($prevFormatter, $column) {
144-
if ($prevFormatter) {
144+
$operation = $this->getOperation($column->getId());
145+
if ($prevFormatter && !($operation === static::OPERATION_IGNORE || $operation instanceof Closure)) {
145146
$value = call_user_func($prevFormatter, $value);
146147
}
147-
$operation = $this->getOperation($column->getId());
148+
// Add value prefix if specified for operation
148149
if ($value !== null && is_string($operation) && array_key_exists($operation, $this->valuePrefixes)) {
149150
$value = $this->valuePrefixes[$operation] . ' ' . $value;
150151
}

0 commit comments

Comments
 (0)