desc = $this->sort === $column ? !$this->desc : false; $this->sort = $column; } // The rows that match, in order. Runs in the browser on every keystroke. #[Computed] public function matching(): array { $query = strtolower(trim($this->query)); $rows = array_filter($this->rows, fn($row) => ($this->status === '' || $row['status'] === $this->status) && ($query === '' || str_contains(strtolower($row['name'] . ' ' . $row['company'] . ' ' . $row['city']), $query))); $sort = $this->sort; usort($rows, fn($a, $b) => $a[$sort] <=> $b[$sort]); return $this->desc ? array_reverse($rows) : $rows; } #[Computed] public function total(): float // float: the sum passes 32-bit int in the browser { return array_sum(array_column($this->matching, 'amount')); } }; ?>

@if ($this->loading('rows')) Loading {{ number_format($size) }} rows… @else {{ number_format(count($this->matching)) }} of {{ number_format(count($rows)) }} rows · ${{ number_format($this->total / 100, 2) }} @endif

@foreach (['id' => '#', 'name' => 'Name', 'company' => 'Company', 'city' => 'City', 'status' => 'Status', 'amount' => 'Amount'] as $column => $label) @endforeach @foreach ($limit ? array_slice($this->matching, 0, $limit) : $this->matching as $row) @endforeach
$sort === $column, 'num' => $column === 'amount' || $column === 'id'])> {{ $label }}{{ $sort === $column ? ($desc ? ' ↓' : ' ↑') : '' }}
{{ $row['id'] }} {{ $row['name'] }} {{ $row['company'] }} {{ $row['city'] }} {{ $row['status'] }} ${{ number_format($row['amount'] / 100, 2) }}