sortField === $field) { $this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc'; } else { $this->sortField = $field; $this->sortDirection = 'asc'; } } // Calculate total pages for pagination public function calculateTotalPages() { return ceil(count($this->rows) / $this->perPage); } // Get the paginated rows for the current page public function getPaginatedRowsProperty() { $sorted = collect($this->rows); if ($this->sortField) { $sorted = $this->sortDirection === 'asc' ? $sorted->sortBy($this->sortField) : $sorted->sortByDesc($this->sortField); } return $sorted ->slice(($this->currentPage - 1) * $this->perPage, $this->perPage) ->values(); } // Set the current page for pagination public function setPage($page) { $this->currentPage = max(1, min($this->calculateTotalPages(), $page)); } public function render() { return view('livewire.components.table', [ 'paginatedRows' => $this->paginatedRows, // 👈 explicitly pass computed property ]); } }