F
Filament11mo ago
Tim

Inline Summaries

Hello, I was wondering if there was a way to use the summeriser for tables in the row itself. in my app I have 2 Models Army.php and Unit.php Armies have many Units and Units have 2 columns I want points and cost I can get a summary at the bottom of the table for the total number of points or the total cost, but can I get one in the table row itself? I'd like the Units column to say "Total Points" with a value of 165. My table function
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name'),
TextColumn::make('units.points')
])
->filters([
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('name'),
TextColumn::make('units.points')
])
->filters([
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
3 Replies
Tim
TimOP11mo ago
Answered my own question, sorry for the post.
TextColumn::make('units')->state(function (Army $army) {
return $army->totalPoints();
})
TextColumn::make('units')->state(function (Army $army) {
return $army->totalPoints();
})
Adrianryff
Adrianryff11mo ago
how you realize summary in diferrents fields i need help summary 5 field to taxes in one fiel total taxes
No description
Tim
TimOP11mo ago
so my totalPoints funciton in the Army model does the calculations. the function within the state call is a callback with acess to the resource record. You can then do whatever calucaltions you want like
TextColumn:make('total_tax')->state(function(Order $order) {
return $numebr1 + $number2 + $number3;
});
TextColumn:make('total_tax')->state(function(Order $order) {
return $numebr1 + $number2 + $number3;
});
Want results from more Discord servers?
Add your server