Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Summary - Defer Loading Fix #1813

Open
wants to merge 2 commits into
base: 6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions resources/views/components/table-footer.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{-- blade-formatter-enable --}}
<tr
class="{{ theme_style($theme, 'table.header.tr') }}"
class="{{ theme_style($theme, 'table.footer.tr') }}"
>
@if (data_get($setUp, 'detail.showCollapseIcon'))
<td
Expand All @@ -20,10 +20,10 @@ class="{{ theme_style($theme, 'table.body.tdSummarize') . ' ' . data_get($column
'labelSum' => data_get($column, 'properties.summarize.sum.label'),

'count' => data_get($column, 'properties.summarize.count.footer') ? data_get($column, 'properties.summarize_values.count') : null,
'labelCount' => data_get($column, 'properties.summarize.count.footer'),
'labelCount' => data_get($column, 'properties.summarize.count.label'),

'min' => data_get($column, 'properties.summarize.min.footer') ? data_get($column, 'properties.summarize_values.min') : null,
'labelMin' => data_get($column, 'properties.summarize.min.footer'),
'labelMin' => data_get($column, 'properties.summarize.min.label'),

'max' => data_get($column, 'properties.summarize.max.footer') ? data_get($column, 'properties.summarize_values.max') : null,
'labelMax' => data_get($column, 'properties.summarize.max.label'),
Expand Down
9 changes: 7 additions & 2 deletions src/DataSource/Processors/DataSourceBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,26 +229,31 @@ protected function applySummaries(MorphToMany|EloquentBuilder|BaseCollection|Que
throw new \InvalidArgumentException('Summary Formatter expects a callable function, ' . gettype($formattingClosure) . ' given instead.');
}

if (in_array($fieldName, [$column->field, $column->dataField])) {
if (in_array($fieldName, [$column['field'], $column['dataField']])) {
$value = $formattingClosure($value);
}

data_set($column, 'properties.summarize_values.' . $summarizeMethod, $value);
}
}

return $column;
}
};

$this->component->columns = collect($this->component->columns)
->map(function (array|\stdClass|Column $column) use ($results, $applySummaryFormat) {
$column = (array) $column;

$field = strval(data_get($column, 'dataField')) ?: strval(data_get($column, 'field'));

$summaries = ['sum', 'count', 'avg', 'min', 'max'];

foreach ($summaries as $summary) {
if (data_get($column, 'properties.summarize.' . $summary . '.header') || data_get($column, 'properties.summarize.' . $summary . '.footer')) {
$value = $results->{$summary}($field);
rescue(fn () => $applySummaryFormat($summary, $column, $field, $value), report: false);
$newColumn = rescue(fn () => $applySummaryFormat($summary, $column, $field, $value), report: false);
$column = is_null($newColumn) ? $column : $newColumn;
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/PowerGridComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public function hydrate(): void
DataSourceBase::$actionsHtml = [];
}

public function dehydrate(): void
{
$this->columns = $this->columns();
}

public function fetchDatasource(): void
{
$this->readyToLoad = true;
Expand Down
Loading