64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Components;
|
|
|
|
use Livewire\Component;
|
|
|
|
class Table extends Component
|
|
{
|
|
public $columns = [];
|
|
public $rows = [];
|
|
public $selected = []; // Holds the selected row IDs
|
|
public $selectAll = false; // To track if 'Select All' is checked
|
|
public $hasActions = false;
|
|
public $isViewPage = false;
|
|
|
|
// Add new methods for handling actions
|
|
public function editRow($rowId)
|
|
{
|
|
// Logic for editing a row (e.g., redirect to the edit page or open modal)
|
|
session()->flash('message', 'Edit action for user ID: ' . $rowId);
|
|
}
|
|
|
|
public function deleteRow($rowId)
|
|
{
|
|
// Logic for deleting a row (e.g., delete from database)
|
|
session()->flash('message', 'Delete action for user ID: ' . $rowId);
|
|
}
|
|
|
|
public function viewRow($rowId)
|
|
{
|
|
// Logic for viewing a row (e.g., redirect to the view page or open a modal)
|
|
session()->flash('message', 'View action for user ID: ' . $rowId);
|
|
}
|
|
|
|
|
|
|
|
public function selectAllRows()
|
|
{
|
|
// Convert rows to a collection if it is an array, then pluck the 'id'
|
|
if ($this->selectAll) {
|
|
$this->selected = collect($this->rows)->pluck('id')->toArray();
|
|
} else {
|
|
$this->selected = [];
|
|
}
|
|
}
|
|
|
|
public function selectRow($rowId)
|
|
{
|
|
if (in_array($rowId, $this->selected)) {
|
|
$this->selected = array_diff($this->selected, [$rowId]);
|
|
} else {
|
|
$this->selected[] = $rowId;
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.components.table');
|
|
}
|
|
}
|
|
|
|
|
|
|