columns = $columns; $this->rows = $rows; } // Update rows based on search public function updatedSearch() { $this->selected = []; } // Select all rows public function selectAllRows() { if ($this->selectAll) { $this->selected = collect($this->rows)->pluck('id')->toArray(); } else { $this->selected = []; } } // Select single row public function selectRow($rowId) { if (in_array($rowId, $this->selected)) { $this->selected = array_diff($this->selected, [$rowId]); } else { $this->selected[] = $rowId; } } // Simplified version public function sortBy($field) { if ($this->sortField === $field) { $this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc'; } else { $this->sortField = $field; $this->sortDirection = 'asc'; } $this->rows = collect($this->rows)->sortBy(function ($row) { return $row[$this->sortField] ?? null; }, SORT_REGULAR, $this->sortDirection === 'desc')->values()->all(); // Use all() to return plain array again } public function render() { return view('livewire.components.table', [ 'rows' => $this->rows, ]); } }