F
Filament13mo ago
Garrita

Summarize in a custom column

Hi guys, how can I summarize this value as a total of a custom column?
TextColumn::make('available_amount')
->summarize(Sum::make())
->label('Monto Disponible')
->state(function (Model $record) {
return $record->availableAmount();
})
TextColumn::make('available_amount')
->summarize(Sum::make())
->label('Monto Disponible')
->state(function (Model $record) {
return $record->availableAmount();
})
I got an error that my table does not find the available_amount column because I know that it's generated.
1 Reply
Tieme
Tieme13mo ago
Hi, I had the same problem. I solved it by loading the original column and than changed the state with the calculation In below column "amount" is the total minutes (colum in database). and with state i show the "hours" witch is in my modal. For summarize i sum all the minutes and than format it to hours.
TextColumn::make('amount')
->state(function (?ProjectHours $record) {
return $record->hours;
})
->sortable()
->summarize(Sum::make()
->formatStateUsing(function ($state) {
$minuten = $state;
$uren = floor($minuten / 60); // Het aantal volledige uren
$resterendeMinuten = $minuten % 60; // De resterende minuten

return sprintf('%02d:%02d', $uren, $resterendeMinuten);
})
->label('Total')
),
TextColumn::make('amount')
->state(function (?ProjectHours $record) {
return $record->hours;
})
->sortable()
->summarize(Sum::make()
->formatStateUsing(function ($state) {
$minuten = $state;
$uren = floor($minuten / 60); // Het aantal volledige uren
$resterendeMinuten = $minuten % 60; // De resterende minuten

return sprintf('%02d:%02d', $uren, $resterendeMinuten);
})
->label('Total')
),
Want results from more Discord servers?
Add your server