laravel-livewire-tables icon indicating copy to clipboard operation
laravel-livewire-tables copied to clipboard

Default sort

Open snapey opened this issue 4 years ago • 3 comments

Is there a way to add a default sort to the view? I can't add it to the query as then it overrides the ability to sort by the other columns later.

snapey avatar May 05 '20 14:05 snapey

I don't know if this is correct, but I overwrote the defaults in the mount method;

    public function mount() 
    {
        $this->setTableProperties();
        $this->sort_attribute = 'name';
        $this->sort_direction = 'asc';
    }

snapey avatar May 05 '20 14:05 snapey

You can use default variables like below:

class UsersTable extends TableComponent
{
    public $sortField = 'id';

    public $sortDirection = 'desc';
}

mkysoft avatar Sep 13 '20 11:09 mkysoft

What works for me is:

    public string $defaultSortColumn = 'id';
    public string $defaultSortDirection = 'desc';

nguillaumin avatar Jan 15 '22 11:01 nguillaumin