Sum of fee column in table footer
I have two tables students and student_fees , in student list page, i am showing student information with fee also, i use getTableContentFooter() to show the sum of fee column but it show 0.
7 Replies
Check this might help.
https://filamentphp.com/tricks/aggregate-data-in-table-footer
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.
i have seen this, my fee data has com form relationship, that's why it show only 0. how can show sum of fee for relationship table
I will update the trick soon to include this option and make it more clear for the relationship tables
The idea is after adding the view
dont add the rest of the code in the getTableContentFooter()ExampleRelationManager``` class file which has the table and form.
that will do.
let me know if works
it's sum the value but on RelationManager view but not on the StudentList Resource view
If you can share the code that is giving you zero also.
the list resource
<?php
namespace App\Filament\Resources\StudentResource\Pages;
use App\Filament\Resources\StudentResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ListRecords;
use Filament\Tables\Filters\Layout;
use Closure;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use App\Models\Student;
use App\Models\StudentCourse;
use Illuminate\Contracts\View\View;
class ListStudents extends ListRecords
{
protected static string $resource = StudentResource::class;
protected function getActions(): array
{
return [
Actions\CreateAction::make(),
];
}
/protected function getTableFiltersLayout(): ?string
{
return Layout::AboveContent;
}/
protected function getTableQuery(): Builder { return Student::query()->where('status', '=', 1); }
public array $data_list= [ 'calc_columns' => [ 'student_course.admission_fee', 'student_course.fee', 'student_course.advance', ], ]; protected function getTableContentFooter(): ?View { return view('tables.footer.student-footer', $this->data_list); } }
protected function getTableQuery(): Builder { return Student::query()->where('status', '=', 1); }
public array $data_list= [ 'calc_columns' => [ 'student_course.admission_fee', 'student_course.fee', 'student_course.advance', ], ]; protected function getTableContentFooter(): ?View { return view('tables.footer.student-footer', $this->data_list); } }
The relation manager file