Ā© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
27 replies
Travis

Is there an error in `Filament\Table\Table::defaultSort()`...?šŸ¤”

I was trying to pass a Closure to
defaultSort()
defaultSort()
for the second argument,
$direction
$direction
for a table that I have.

Here is the latest version of
defaultSort()
defaultSort()
in
Filament\Tables\Table
Filament\Tables\Table
:
trait CanSortRecords
{
    protected ?string $defaultSortColumn = null;

    protected ?string $defaultSortDirection = null;

    protected ?Closure $defaultSortQuery = null;

    protected bool | Closure | null $persistsSortInSession = false;

    public function defaultSort(string | Closure | null $column, string | Closure | null $direction = 'asc'): static
    {
        if ($column instanceof Closure) {
            $this->defaultSortQuery = $column;
        } else {
            $this->defaultSortColumn = $column;
        }

        if ($direction !== null) {
            $direction = Str::lower($direction);
        }

        $this->defaultSortDirection = $direction;

        return $this;
    }
trait CanSortRecords
{
    protected ?string $defaultSortColumn = null;

    protected ?string $defaultSortDirection = null;

    protected ?Closure $defaultSortQuery = null;

    protected bool | Closure | null $persistsSortInSession = false;

    public function defaultSort(string | Closure | null $column, string | Closure | null $direction = 'asc'): static
    {
        if ($column instanceof Closure) {
            $this->defaultSortQuery = $column;
        } else {
            $this->defaultSortColumn = $column;
        }

        if ($direction !== null) {
            $direction = Str::lower($direction);
        }

        $this->defaultSortDirection = $direction;

        return $this;
    }


Seems like passing
$direction
$direction
to
Str::lower()
Str::lower()
when
$direction
$direction
is a Closure causes an exception:
mb_strtolower(): Argument #1 ($string) must be of type string, Closure given
mb_strtolower(): Argument #1 ($string) must be of type string, Closure given


Am I doing this wrong, or is this an error...? Seems like this is an error to me.
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

table ->defaultSort()
FilamentFFilament / ā“ā”Šhelp
12mo ago
defaultSort() with an enum
FilamentFFilament / ā“ā”Šhelp
9mo ago
Testing filament resource table got an error
FilamentFFilament / ā“ā”Šhelp
2y ago
Filament Table in Blade
FilamentFFilament / ā“ā”Šhelp
2y ago