FilamentF
Filament•3y ago
Travis

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

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

Here is the latest version of defaultSort() in 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;
    }


Seems like passing $direction to Str::lower() when $direction is a Closure causes an exception: 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.
Was this page helpful?