Skip to content

Commit eb8f643

Browse files
Feature/update readme v009 (#20)
1 parent 508fc56 commit eb8f643

File tree

10 files changed

+39
-42
lines changed

10 files changed

+39
-42
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ This package **requires Livewire** and cannot be used without it. To integrate D
5858
['column' => 'email_verified_at', 'type' => 'checkbox', 'options' => ['1' => 'Verified', 'null' => 'Not Verified'], 'label' => 'Email bevestigd'],
5959
['column' => 'email_verified_at', 'type' => 'select', 'options' => ['1' => 'Verified', 'null' => 'Not Verified'], 'label' => 'Email bevestigd'],
6060
]"
61-
:actions="[
61+
:rows-actions="[
6262
['name' => 'edit', 'label' => 'Edit', 'route' => 'users.datatable.export'],
6363
['name' => 'delete', 'label' => 'Delete', 'route' => 'users.datatable.export'],
6464
['name' => 'view', 'label' => 'View Profile', 'url' => '/users/{id}']
6565
]"
66-
:bulkActions="[
66+
:bulk-actions="[
6767
'export' => ['label' => 'Export', 'route' => 'users.datatable.export']
6868
]"
6969
/>
@@ -110,12 +110,12 @@ Sorting is supported for all columns in the dataset, including text, dates, and
110110

111111
---
112112

113-
## Actions & Bulk Actions
113+
## Row Actions & Bulk Actions
114114

115115
### Row Actions
116116

117117
```blade
118-
:actions="[
118+
:row-actions="[
119119
['label' => 'Edit', 'route' => 'users.edit', 'class' => 'bg-green-500 text-white px-3 py-1 rounded'],
120120
['label' => 'Delete', 'url' => 'users/{id}', 'class' => 'bg-red-500 text-white px-3 py-1 rounded', 'onclick' => 'return confirm(\'Are you sure?\')']
121121
]"
@@ -124,7 +124,7 @@ Sorting is supported for all columns in the dataset, including text, dates, and
124124
### Bulk Actions
125125

126126
```blade
127-
:bulkActions="[
127+
:bulk-actions="[
128128
'delete' => ['label' => 'Delete', 'route' => 'users.bulk.delete'],
129129
'export' => ['label' => 'Export', 'route' => 'users.bulk.export']
130130
]"

resources/views/vendor/datatables/actions.blade.php

Lines changed: 0 additions & 11 deletions
This file was deleted.

resources/views/vendor/datatables/components/bulk-action.blade.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<label class="text-sm text-gray-600">{{ __('datatable::datatables.bulk_actions') }}</label>
21
<select wire:model="bulkAction"
32
class="border border-gray-300 rounded-lg px-3 py-2 text-sm w-48 focus:ring-2 focus:ring-blue-400 transition">
43
<option value="">{{ __('datatable::datatables.select_option') }}</option>

resources/views/vendor/datatables/components/mobile/table.blade.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ class="h-5 w-5 text-blue-500 border-gray-300 rounded focus:ring-2 focus:ring-blu
1010
</div>
1111
<div class="grid gap-2 text-sm text-gray-700">
1212
@foreach($columns as $column)
13-
@if(!in_array($column, $hiddenColumns))
13+
@if(!in_array($column['column'], $hiddenColumns))
1414
<div class="flex justify-between border-b pb-1">
15-
<strong>{{ $columnLabels[$column] ?? ucfirst(str_replace('_', ' ', $column)) }}:</strong>
16-
<span>{{ $row->$column }}</span>
15+
<strong>{{ ucfirst($column['column']) }}:</strong>
16+
<span>{{ $row->{$column['column']} }}</span>
1717
</div>
1818
@endif
1919
@endforeach
2020
</div>
2121

2222
{{-- ✅ Acties onderaan voor mobiel --}}
2323
<div class="mt-3 flex flex-wrap gap-2">
24-
@includeIf($actionsView, ['row' => $row])
24+
@includeIf($rowActionView, ['row' => $row])
2525
</div>
2626
</div>
2727
@endforeach
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<div class="hidden md:block">
2-
<label for="perPage" class="text-sm text-gray-600">{{ __('datatable::datatables.results_per_page') }}</label>
32
<select wire:change="updatePerPage($event.target.value)" id="perPage"
43
class="border border-gray-300 rounded-lg px-3 py-2 text-sm w-24 focus:ring-2 focus:ring-blue-400 transition">
54
<option value="10">10</option>
65
<option value="25">25</option>
76
<option value="50">50</option>
87
<option value="100">100</option>
98
</select>
10-
9+
<label for="perPage" class="text-sm text-gray-600">{{ __('datatable::datatables.results_per_page') }}</label>
1110
</div>

resources/views/vendor/datatables/components/table.blade.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ class="h-5 w-5 text-blue-500 border-gray-300 rounded focus:ring-2 focus:ring-blu
99
</th>
1010
@endif
1111
@foreach($columns as $column)
12-
@if(!in_array($column, $hiddenColumns))
12+
@if(!in_array($column['column'], $hiddenColumns))
1313
<th class="px-4 py-3 text-left text-sm font-semibold text-gray-700 border cursor-pointer hover:bg-gray-100 transition"
14-
wire:click="sortBy('{{ $column }}')">
14+
wire:click="sortBy('{{ $column['column'] }}')">
1515
<div class="flex items-center">
16-
{{ $columnLabels[$column] ?? ucfirst(str_replace('_', ' ', $column)) }}
17-
@if ($sortColumn === $column)
16+
{{ ucfirst($column['label']) }}
17+
@if ($sortColumn === $column['column'])
1818
<span class="ml-2 text-blue-500">
1919
@if ($sortDirection === 'asc')
2020
@@ -45,14 +45,14 @@ class="h-5 w-5 text-blue-500 border-gray-300 rounded focus:ring-2 focus:ring-blu
4545
</td>
4646
@endif
4747
@foreach($columns as $column)
48-
@if(!in_array($column, $hiddenColumns))
48+
@if(!in_array($column['column'], $hiddenColumns))
4949
<td class="px-4 py-3 border text-sm text-gray-700">
50-
{{ $row->$column }}
50+
{{ $row->{$column['column']} }}
5151
</td>
5252
@endif
5353
@endforeach
5454
<td class="px-4 py-3 border">
55-
@includeIf($actionsView, ['row' => $row])
55+
@includeIf($rowActionView, ['row' => $row])
5656
</td>
5757
</tr>
5858
@endforeach

resources/views/vendor/datatables/datatable.blade.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
@includeIf('datatable::components.bulk-action')
3131
</div>
3232
@endif
33-
3433
</div>
3534

3635
<div class="overflow-x-auto">
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="flex items-center space-x-2">
2+
@foreach($rowActions as $action)
3+
<a href="{{ isset($action['route']) ? route($action['route'], $row->id) : (isset($action['url']) ? str_replace('{id}', $row->id, $action['url']) : '#') }}"
4+
onclick="event.stopPropagation();"
5+
@foreach($action['attributes'] ?? [] as $key => $value)
6+
{{ $key }}="{{ $value }}"
7+
@endforeach>
8+
{{ $action['label'] }}
9+
</a>
10+
@endforeach
11+
</div>

src/Livewire/DataTableComponent.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class DataTableComponent extends Component
2727
public array $columns = [];
2828

2929
/** @var array List of actions available for each row */
30-
public array $actions = [];
30+
public array $rowActions = [];
3131

3232
/** @var string The Blade view file for displaying row actions */
33-
public string $actionsView = 'datatable::actions';
33+
public string $rowActionView = 'datatable::row-actions';
3434

3535
/** @var string The search query entered by the user */
3636
#[\Livewire\Attributes\Url(history: true)]
@@ -79,26 +79,26 @@ class DataTableComponent extends Component
7979
*
8080
* @param string $model The model class name.
8181
* @param array $columns List of table columns.
82-
* @param array $actions Row actions.
83-
* @param string $actionsView Blade view for row actions.
82+
* @param array rowActions
83+
* @param string $rowActionView Blade view for row actions.
8484
* @param array $hiddenColumns Columns that should be hidden.
8585
* @param array $bulkActions Available bulk actions.
8686
* @param array $filters Initial filters.
8787
*/
8888
public function mount(
8989
string $model,
9090
array $columns,
91-
array $actions = [],
92-
string $actionsView = 'datatable::actions',
91+
array $rowActions = [],
92+
string $rowActionView = 'datatable::row-actions',
9393
array $hiddenColumns = [],
9494
array $bulkActions = [],
9595
array $filters = []
9696
): void
9797
{
9898
$this->model = $model;
9999
$this->columns = $columns;
100-
$this->actions = array_map(fn($action) => $action instanceof Action ? $action->toArray() : $action, $actions);
101-
$this->actionsView = $actionsView;
100+
$this->rowAction = array_map(fn($action) => $action instanceof Action ? $action->toArray() : $action, $rowActions);
101+
$this->rowActionView = $rowActionView;
102102
$this->hiddenColumns = $hiddenColumns;
103103
$this->bulkActions = $bulkActions;
104104
$this->filters = collect($filters)
@@ -319,8 +319,8 @@ public function render(): View
319319
return view('datatable::datatable', [
320320
'rows' => $this->getRows(),
321321
'columns' => $this->columns,
322-
'actions' => $this->actions,
323-
'actionsView' => $this->actionsView,
322+
'rowActions' => $this->rowActions,
323+
'rowActionView' => $this->rowActionView,
324324
'hiddenColumns' => $this->hiddenColumns,
325325
'selectedRows' => $this->selectedRows,
326326
'selectAll' => $this->selectAll,

src/Search.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function apply(Builder $query, array $columns): Builder
4141
if (!empty($this->searchTerm)) {
4242
$query->where(function (Builder $q) use ($columns) {
4343
foreach ($columns as $column) {
44-
$q->orWhere($column, 'like', "%{$this->searchTerm}%");
44+
$q->orWhere($column['column'], 'like', "%{$this->searchTerm}%");
4545
}
4646
});
4747
}

0 commit comments

Comments
 (0)