Skip to content

Commit 09448e6

Browse files
committed
Ability to add a link to make table rows clickable
1 parent d3201db commit 09448e6

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
99
### Added
1010

1111
- Arabic translations
12+
- Ability to add a link to make table rows clickable
1213

1314
### Changed
1415

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ public function setTableRowId($model) : ?string;
250250
*/
251251
public function setTableRowAttributes($model) : array;
252252

253+
/**
254+
* Return a URL to go to when the table row is clicked
255+
*/
256+
public function getTableRowUrl($model): ?string;
257+
253258
/**
254259
* Used to set the class of a table cell based on the column and the value of the cell
255260
*/

resources/views/includes/_body.blade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class="{{ $this->setTableRowClass($model) }}"
1717
@foreach ($this->setTableRowAttributes($model) as $key => $value)
1818
{{ $key }}="{{ $value }}"
1919
@endforeach
20+
@if ($this->getTableRowUrl($model))
21+
onclick="window.location='{{ $this->getTableRowUrl($model) }}';"
22+
style="cursor:pointer"
23+
@endif
2024
>
2125
@if($checkbox && $checkboxLocation === 'left')
2226
@include('laravel-livewire-tables::includes._checkbox-row')

src/Traits/Table.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ public function setTableRowAttributes($model): array
114114
return [];
115115
}
116116

117+
/**
118+
* @param $model
119+
*
120+
* @return string|null
121+
*/
122+
public function getTableRowUrl($model): ?string
123+
{
124+
return null;
125+
}
126+
117127
/**
118128
* @param $attribute
119129
* @param $value

0 commit comments

Comments
 (0)