how to group by salary range with filament table

I have a requirement to group by annual salary my users table have a monthly_salary column I want to do a filament table grouping that will group the users to the following group annual salary < 50000 annual salary < 80000 annual salary >= 80000 But not quite sure how to do it. So far I did the following
public function table(Table $table): Table
{
return $table
->groups([
Group::make('montly_salary')
->label('Annual Salary')
->titlePrefixedWithLabel(false)
->getTitleFromRecordUsing(function (User $record): string {
if ($record->monthly_salary * 12 < 50_000) {
return '< 50,000';
}

if ($record->monthly_salary * 12 < 80_000) {
return '50,000 to < 80,000';
}

return '$80,000 and above';
})
->getKeyFromRecordUsing(function (ListedLoanApplication $record): string {
if ($record->monthly_salary * 12 < 50_000) {
return '< 50,000';
}

if ($record->monthly_salary * 12 < 80_000) {
return '50,000 to < 80,000';
}

return '$80,000 and above';
}),
]);
}
public function table(Table $table): Table
{
return $table
->groups([
Group::make('montly_salary')
->label('Annual Salary')
->titlePrefixedWithLabel(false)
->getTitleFromRecordUsing(function (User $record): string {
if ($record->monthly_salary * 12 < 50_000) {
return '< 50,000';
}

if ($record->monthly_salary * 12 < 80_000) {
return '50,000 to < 80,000';
}

return '$80,000 and above';
})
->getKeyFromRecordUsing(function (ListedLoanApplication $record): string {
if ($record->monthly_salary * 12 < 50_000) {
return '< 50,000';
}

if ($record->monthly_salary * 12 < 80_000) {
return '50,000 to < 80,000';
}

return '$80,000 and above';
}),
]);
}
However it doesn't work, i figured i prob need to use ->groupQueryUsing() but not quire sure how do i write the query code since this is not a simple group by status https://filamentphp.com/docs/3.x/tables/grouping Thank you
1 Reply
CalumThomson
CalumThomson9mo ago
I have the same requirement, but to group by age bands ( under 18, 18-30, over 75 etc...). Is this kind of row grouping within ranges (or bins or buckets) possible with Filament?

Did you find this page helpful?