F
Filament14mo ago
d3v1anX

Bug? Custom summarize with groups

Hi, I don't know if this is maybe a bug: I have the following table-code:
return $table
->groups([
Group::make('user.name'),
Group::make('start')->label('Start date (UTC)')->date(),
])
// [...]
->columns([
Tables\Columns\TextColumn::make('start')
->date()
->label('Start date (UTC)')
->icon('heroicon-o-calendar')
->sortable(query: function (Builder $query, string $direction) {
$query->orderBy('start', $direction);
}),
Tables\Columns\TextColumn::make('start_time')
->label('Start time (UTC)')
->getStateUsing(fn (Model $record) => $record->start)
->icon('heroicon-o-arrow-left-on-rectangle')

->time()
->sortable(query: function (Builder $query, string $direction) {
$query->orderByRaw('TIME(start) '.$direction);
}),
Tables\Columns\TextColumn::make('end')
->label('End time (UTC)')
->icon('heroicon-o-arrow-right-on-rectangle')
->time()
->sortable(query: function (Builder $query, string $direction) {
$query->orderByRaw('TIME(end) '.$direction);
}),
Tables\Columns\TextColumn::make('duration')
->state(fn (Model $record) => CarbonInterval::seconds($record->duration)->cascade()->format('%H:%I:%S'))
->sortable()
->icon('heroicon-o-clock')
->summarize(
Tables\Columns\Summarizers\Summarizer::make()->using(function ($query): string {
return DateService::fromSecondsToHours($query->sum('duration'));
})
),
)];
return $table
->groups([
Group::make('user.name'),
Group::make('start')->label('Start date (UTC)')->date(),
])
// [...]
->columns([
Tables\Columns\TextColumn::make('start')
->date()
->label('Start date (UTC)')
->icon('heroicon-o-calendar')
->sortable(query: function (Builder $query, string $direction) {
$query->orderBy('start', $direction);
}),
Tables\Columns\TextColumn::make('start_time')
->label('Start time (UTC)')
->getStateUsing(fn (Model $record) => $record->start)
->icon('heroicon-o-arrow-left-on-rectangle')

->time()
->sortable(query: function (Builder $query, string $direction) {
$query->orderByRaw('TIME(start) '.$direction);
}),
Tables\Columns\TextColumn::make('end')
->label('End time (UTC)')
->icon('heroicon-o-arrow-right-on-rectangle')
->time()
->sortable(query: function (Builder $query, string $direction) {
$query->orderByRaw('TIME(end) '.$direction);
}),
Tables\Columns\TextColumn::make('duration')
->state(fn (Model $record) => CarbonInterval::seconds($record->duration)->cascade()->format('%H:%I:%S'))
->sortable()
->icon('heroicon-o-clock')
->summarize(
Tables\Columns\Summarizers\Summarizer::make()->using(function ($query): string {
return DateService::fromSecondsToHours($query->sum('duration'));
})
),
)];
The summarize function works as expected on the buttom of the table. Unfortunately the group-summaries seems like there is something wrong. Already found: https://github.com/filamentphp/filament/issues/7578 but it seems already solved by @Dan Harrin - I don't know it this is related to it. Has anyone an idea? Or is it possible to customize the summarize-function just for the groups?
GitHub
Incorrect per-group aggregate values in tables · Issue #7578 · fila...
Package filament/filament Package Version v3.0.7 Laravel Version v10.x Livewire Version v3.x PHP Version = 8.1 Problem description When grouping by a column in a table, per-group aggregates (sum in...
4 Replies
d3v1anX
d3v1anXOP14mo ago
No description
Dan Harrin
Dan Harrin14mo ago
Please open an issue with a simple reproduction
d3v1anX
d3v1anXOP14mo ago
Sure, thank you Dan 😊
d3v1anX
d3v1anXOP14mo ago
GitHub
Bug with custom summarize in groupings · Issue #9073 · filamentphp/...
Package filament/filament Package Version v3.0.74 Laravel Version v10.28.0 Livewire Version v3.0.8 PHP Version PHP 8.2.11 Problem description With custom summarize-functions and grouping the summar...
Want results from more Discord servers?
Add your server