How do we get getTableContentFooter() to work with calculated fields?

I followed the trick for Aggregate Data in Table Footer https://filamentphp.com/tricks/aggregate-data-in-table-footer and it worked nicely to sum a field. But it does not recognize the calculated field.
I tried it with the ID field and it works to sum the ids in the footer (Just a test you know.) When I made a calculated field from id with TextColumn::make('id_test') ->getStateUsing(function(Schedule $record) { return $record->id; }), it returns the id on each line but it will not sum in the footer rather displays a 0. My real data is minutes in a schedule but the ID example is easy to follow...
Filament
Aggregate data in table footer (sum, avg...etc) by moaaz faracheh -...
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
Solution:
I think I'll start with the footer, the two values are strings of time that I need to carbon->diffInMinutes resulting in minutes to be summed then formatted as HH:MM
Jump to solution
4 Replies
Patrick Boivin
I think the data has to be on the Eloquent query (like most other table features like sort, search, etc.)
ddoddsr
ddoddsrOP2y ago
So I would perform the calc in the footer?
Patrick Boivin
Yeah this could be a simple solution Another option would be to add the aggregate function to your query (e.g. withSum()) https://laravel.com/docs/10.x/eloquent-relationships#other-aggregate-functions
Solution
ddoddsr
ddoddsr2y ago
I think I'll start with the footer, the two values are strings of time that I need to carbon->diffInMinutes resulting in minutes to be summed then formatted as HH:MM
Want results from more Discord servers?
Add your server