FilamentF
Filament16mo ago
ddoddsr

summarize calculated fields in footer

How can I add a custom calculation to the footer of a grouped table?
These three columns show up great for each row and the footer group summarize works for the first two.
Just cannot figure out the summarize for the third calculated column...
Trying a custom summarizer:

TextColumn::make('leads_sum_connect_req')
    ->sum('leads', 'connect_req')
    ->summarize(Sum::make()->label('ConnctReq'))
    ->label('ConnctReq')
    ->description('ConnctReq'),

TextColumn::make('leads_sum_connected')
    ->sum('leads', 'connected')
    ->summarize(Sum::make()->label('Connected'))
    ->label('Connected')
    ->description('Connected'),

TextColumn::make('connected_percent')
    ->state(function($record){
        return ( $record->leads_generated->sum('connected')) / ($record->leads_generated->sum('connection_request')+ .01) * 100;
    })
    ->sortable()
    ->numeric(decimalPlaces: 1)
    ->summarize(
        Summarizer::make()
        ->label('Connected %')
        ->using(function($record){  // , but [$record] was unresolvable.
            return 99.9 ; // to test
            return ( $record->leads_generated->sum('connected')) 
                  / ($record->leads_generated->sum('connection_request')+ .01) * 100;
        })
)


With this I get an error:
An attempt was made to evaluate a closure for [Filament\Tables\Columns\Summarizers\Summarizer], but [$record] was unresolvable.
Was this page helpful?