Table Summarize value based on state

I have a table column called cost, I've added a summarize attributes. How can I summarize all value based on state value?
Tables\Columns\TextColumn::make('cost')
->alignRight()
->state(function ($record) {
return costFormula($record->field1, $record->cost);
})
->summarize(Tables\Columns\Summarizers\Sum::make())
->numeric()
->prefix('$')
->sortable(),
Tables\Columns\TextColumn::make('cost')
->alignRight()
->state(function ($record) {
return costFormula($record->field1, $record->cost);
})
->summarize(Tables\Columns\Summarizers\Sum::make())
->numeric()
->prefix('$')
->sortable(),
Currently, the summarize value is based on the original data from database. I want it to be from ->state value
Solution:
You could try a custom model property and add that to a new column? Or maybe add a column in the table and adjust it with ->formatStateUsing(function() { })
Jump to solution
7 Replies
lazydog
lazydogOP2d ago
Temporarily, I will add a new column for this.
Solution
biebthesecond
biebthesecond2d ago
You could try a custom model property and add that to a new column? Or maybe add a column in the table and adjust it with ->formatStateUsing(function() { })
lazydog
lazydogOP2d ago
I will make it a try about the custom model property like the append does. if its not, new table column wil be better 🙂
biebthesecond
biebthesecond2d ago
Table column meaning database table column? or filament table?
lazydog
lazydogOP2d ago
$appends is working!
biebthesecond
biebthesecond2d ago
Perfect! I'd say check this thread as solved then
lazydog
lazydogOP2d ago
Don't worry, I always did that. thanks

Did you find this page helpful?