Skip to content

Commit 28cb932

Browse files
committed
Merge branch 'adamwoodhead-master' into develop
2 parents e9bf953 + 810b43d commit 28cb932

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

docs/rows/clickable-rows.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,21 @@ public function redirectToModel(string $name, array $parameters = [], $absolute
5353
```
5454

5555
Now the blank space of the row should have its action, while your links go to their own action.
56+
57+
## Working with `wire:click` on rows
58+
59+
You can add the row-level Livewire clicks by utilizing the following method.
60+
61+
```php
62+
public function getTableRowWireClick($row): ?string
63+
{
64+
return "doSomething(" . $row->id . ")";
65+
}
66+
67+
public function doSomething($id)
68+
{
69+
// ...
70+
}
71+
```
72+
73+
If you state both `getTableRowUrl` & `getTableRowWireClick`, the URL will supersede when a non-null value is supplied.

resources/views/bootstrap-4/includes/table.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
:reordering="$reordering"
9999
:url="method_exists($this, 'getTableRowUrl') ? $this->getTableRowUrl($row) : ''"
100100
:target="method_exists($this, 'getTableRowUrlTarget') ? $this->getTableRowUrlTarget($row) : '_self'"
101+
:wireclick="method_exists($this, 'getTableRowWireClick') ? $this->getTableRowWireClick($row) : ''"
101102
:class="method_exists($this, 'setTableRowClass') ? ' ' . $this->setTableRowClass($row) : ''"
102103
:id="method_exists($this, 'setTableRowId') ? $this->setTableRowId($row) : ''"
103104
:customAttributes="method_exists($this, 'setTableRowAttributes') ? $this->setTableRowAttributes($row) : []"

resources/views/bootstrap-5/includes/table.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class="form-check-input"
9999
:reordering="$reordering"
100100
:url="method_exists($this, 'getTableRowUrl') ? $this->getTableRowUrl($row) : ''"
101101
:target="method_exists($this, 'getTableRowUrlTarget') ? $this->getTableRowUrlTarget($row) : '_self'"
102+
:wireclick="method_exists($this, 'getTableRowWireClick') ? $this->getTableRowWireClick($row) : ''"
102103
:class="method_exists($this, 'setTableRowClass') ? ' ' . $this->setTableRowClass($row) : ''"
103104
:id="method_exists($this, 'setTableRowId') ? $this->setTableRowId($row) : ''"
104105
:customAttributes="method_exists($this, 'setTableRowAttributes') ? $this->setTableRowAttributes($row) : []"

resources/views/tailwind/components/table/row.blade.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@props(['url' => null, 'target' => '_self', 'reordering' => false, 'customAttributes' => []])
1+
@props(['url' => null, 'wireclick' => null, 'target' => '_self', 'reordering' => false, 'customAttributes' => []])
22

33
@if (!$reordering && (method_exists($attributes, 'has') ? $attributes->has('wire:sortable.item') : array_key_exists('wire:sortable.item', $attributes->getAttributes())))
44
@php
@@ -7,10 +7,12 @@
77
@endif
88

99
<tr
10-
{{ $attributes->merge($customAttributes)->merge(['class' => $url ? 'cursor-pointer' : '']) }}
10+
{{ $attributes->merge($customAttributes)->merge(['class' => ($url || $wireclick) ? 'cursor-pointer' : '']) }}
1111

1212
@if ($url)
1313
onclick="window.open('{{ $url }}', '{{ $target }}')"
14+
@elseif ($wireclick)
15+
wire:click="{{ $wireclick }}"
1416
@endif
1517
>
1618
{{ $slot }}

resources/views/tailwind/includes/table.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class="rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150
101101
:reordering="$reordering"
102102
:url="method_exists($this, 'getTableRowUrl') ? $this->getTableRowUrl($row) : ''"
103103
:target="method_exists($this, 'getTableRowUrlTarget') ? $this->getTableRowUrlTarget($row) : '_self'"
104+
:wireclick="method_exists($this, 'getTableRowWireClick') ? $this->getTableRowWireClick($row) : ''"
104105
:class="
105106
($index % 2 === 0 ?
106107
'bg-white dark:bg-gray-700 dark:text-white' . (method_exists($this, 'getTableRowUrl') ? ' hover:bg-gray-100' : '') :

0 commit comments

Comments
 (0)