diff --git a/app/Livewire/Components/Table.php b/app/Livewire/Components/Table.php index 80c04c1..8bcaefa 100644 --- a/app/Livewire/Components/Table.php +++ b/app/Livewire/Components/Table.php @@ -19,6 +19,31 @@ class Table extends Component public $sortField = null; // Column to sort public $sortDirection = 'asc'; // Default sort direction + // Inside App\Livewire\Components\Table + +public $showModal = false; +public $modalMode = 'view'; // or 'edit' +public $modalData = []; + +public function viewRow($id) +{ + $this->modalData = collect($this->rows)->firstWhere('id', $id) ?? []; + $this->modalMode = 'view'; + $this->showModal = true; +} + +public function editRow($id) +{ + $this->modalData = collect($this->rows)->firstWhere('id', $id) ?? []; + $this->modalMode = 'edit'; + $this->showModal = true; +} + +public function closeModal() +{ + $this->showModal = false; + $this->modalData = []; +} public function mount($columns, $rows, $addRoute = null) { @@ -53,7 +78,7 @@ class Table extends Component } } - // Simplified version + // Sorting public function sortBy($field) { if ($this->sortField === $field) { diff --git a/resources/views/livewire/components/table.blade.php b/resources/views/livewire/components/table.blade.php index fbbf26d..6dbf7c9 100644 --- a/resources/views/livewire/components/table.blade.php +++ b/resources/views/livewire/components/table.blade.php @@ -2,90 +2,126 @@
- - @if ($hasAddButton && $addRoute) - - + Add - - @endif + @if ($hasAddButton && $addRoute) + + + Add + + @endif
@if ($hasCheckbox) - + @endif @foreach ($columns as $column) - + @endforeach @if ($hasActions) - + @endif @forelse ($rows as $row) - - @if ($hasCheckbox) - - @endif + + @if ($hasCheckbox) + + @endif - @foreach ($columns as $column) - - @endforeach + @foreach ($columns as $column) + + @endforeach - @if ($hasActions) - + @if ($hasActions) + + + @endif + @if ($showModal) +
+
+
+

+ {{ $modalMode === 'view' ? 'View Details' : 'Edit Details' }} +

+ +
+
+ @foreach ($columns as $column) +
+ + @if ($modalMode === 'edit') + + @else +
+ {{ $modalData[$column['field']] ?? '' }} +
+ @endif +
+ @endforeach +
+ @if ($modalMode === 'edit') +
+ +
+ @endif +
+
+ @endif + @empty - - - + + + @endforelse
- - + + - {{ $column['label'] }} - @if ($sortField === $column['field']) - @if ($sortDirection === 'asc') - - @else - - @endif - @else - - @endif - + {{ $column['label'] }} + @if ($sortField === $column['field']) + @if ($sortDirection === 'asc') + + @else + + @endif + @else + + @endif + ActionsActions
- -
+ + - {{ $row[$column['field']] ?? '' }} - + {{ $row[$column['field']] ?? '' }} + - @if($isViewPage) - - @else - - - - @endif - + @if($isViewPage) + + @else + + + @endif -
No data available
No data available
- + \ No newline at end of file