Livewire

Building Data Tables with Livewire v4

February 01, 2026 1 min read 14 views

Build powerful data tables.

Component

@php
use Livewire\WithPagination;
use Livewire\Attributes\Url;

new class extends Livewire\Component {
    use WithPagination;
    
    #[Url]
    public string $search = '';
    
    #[Url]
    public string $sortBy = 'created_at';
    
    #[Url]
    public string $sortDir = 'desc';
    
    public function sort(string $column): void
    {
        $this->sortDir = $this->sortBy === $column && $this->sortDir === 'asc' ? 'desc' : 'asc';
        $this->sortBy = $column;
    }
}
@endphp
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!