© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
8 replies
Andrew Wallo

Help Needed with Sorting an Accessor in Filament Table

I'm working on a Filament table where I need to display and sort by a computed accessor,
formatted_ending_balance
formatted_ending_balance
, in my
Account
Account
model. The accessor calculates the ending balance based on account transactions and formats it.

Account model:
class Account extends Model
{
    public function formattedEndingBalance(): Attribute
    {
        return Attribute::get(function () {
            return $this->ending_balance->convert()->formatWithCode();
        });
    }

    protected function endingBalance(): Attribute
    {
        return Attribute::get(function () {
            $company = $this->company;
            $fiscalYearStart = $company->locale->fiscalYearStartDate();
            $fiscalYearEnd = $company->locale->fiscalYearEndDate();

            return Accounting::getEndingBalance($this, $fiscalYearStart, $fiscalYearEnd);
        });
    }
    // Unrelated code...
class Account extends Model
{
    public function formattedEndingBalance(): Attribute
    {
        return Attribute::get(function () {
            return $this->ending_balance->convert()->formatWithCode();
        });
    }

    protected function endingBalance(): Attribute
    {
        return Attribute::get(function () {
            $company = $this->company;
            $fiscalYearStart = $company->locale->fiscalYearStartDate();
            $fiscalYearEnd = $company->locale->fiscalYearEndDate();

            return Accounting::getEndingBalance($this, $fiscalYearStart, $fiscalYearEnd);
        });
    }
    // Unrelated code...


Filament table column:
Tables\Columns\TextColumn::make('account.formatted_ending_balance')
    ->localizeLabel('Current Balance')
    ->alignment(Alignment::End)
    ->sortable(),
Tables\Columns\TextColumn::make('account.formatted_ending_balance')
    ->localizeLabel('Current Balance')
    ->alignment(Alignment::End)
    ->sortable(),


The problem is that when I try to sort by
formatted_ending_balance
formatted_ending_balance
, I get a SQL error because this accessor is not a database column. How can I enable sorting for this computed accessor in the Filament table? Is it currently possible? Any possible workarounds or similar solutions? Making it a database column is not an option for me based on my app logic. Thanks.
Solution
You can’t. Sorting is done on DB level. If a db column is not an option you can sort.
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Filament table sorting Bug
FilamentFFilament / ❓┊help
3y ago
Table with accessor content
FilamentFFilament / ❓┊help
3y ago
Help Needed with ToggleButtons in Filament Form
FilamentFFilament / ❓┊help
2y ago
Help Needed with cursorPaginate in Filament Tables with Tabs and Filters
FilamentFFilament / ❓┊help
13mo ago