Skip to content

Commit 3425ebd

Browse files
committed
Row/Cell Formatting
- Added `setTableRowClass`, `setTableRowId`, `setTableRowAttributes`, `setTableDataClass`, `setTableDataId`, `setTableDataAttributes` methods to modify cells and rows depending on data for non-custom rows. - Removed default bg-white on tailwind row component because it was a duplicate, add custom attributes support - Modify all row-columns to accept new fields - Modify all cells to accept customAttributes - Modify all table rows to accept new fields - Use custom cells in bs4/5 row-column views for consistency.
1 parent 8d3e19d commit 3425ebd

File tree

13 files changed

+52
-19
lines changed

13 files changed

+52
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
44

55
## [Unreleased]
66

7-
## [1.8.0] - 2021-06-XX
7+
## [1.8.0] - 2021-06-06
88

99
### Added
1010

1111
- [Actual default sorting](https://github.com/rappasoft/laravel-livewire-tables/pull/313)
1212
- [Added place to put modals in the scope of the component](https://github.com/rappasoft/laravel-livewire-tables/wiki/Working-with-modals)
13+
- Added `setTableRowClass`, `setTableRowId`, `setTableRowAttributes`, `setTableDataClass`, `setTableDataId`, `setTableDataAttributes` methods to modify cells and rows depending on data for non-custom rows.
1314

1415
### Changed
1516

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
<td {{ $attributes }}>
1+
@props(['customAttributes' => []])
2+
3+
<td {{ $attributes->merge($customAttributes) }}>
24
{{ $slot }}
35
</td>
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
@foreach($columns as $column)
22
@if ($column->isVisible())
3-
<td>
3+
<x-livewire-tables::bs4.table.cell
4+
:class="method_exists($this, 'setTableDataClass') ? $this->setTableDataClass($column, $row) : ''"
5+
:id="method_exists($this, 'setTableDataId') ? $this->setTableDataId($column, $row) : ''"
6+
:customAttributes="method_exists($this, 'setTableDataAttributes') ? $this->setTableDataAttributes($column, $row) : []"
7+
>
48
@if ($column->asHtml)
59
{{ new \Illuminate\Support\HtmlString($column->formatted($row)) }}
610
@else
711
{{ $column->formatted($row) }}
812
@endif
9-
</td>
13+
</x-livewire-tables::bs4.table.cell>
1014
@endif
1115
@endforeach

resources/views/bootstrap-4/components/table/row.blade.php

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

33
<tr
4-
{{ $attributes }}
4+
{{ $attributes->merge($customAttributes) }}
55

66
@if ($url)
77
onclick="window.location='{{ $url }}';"

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
<x-livewire-tables::bs4.table.row
3434
wire:loading.class.delay="text-muted"
3535
wire:key="table-row-{{ $row->getKey() }}"
36-
:url="method_exists($this, 'getTableRowUrl') ? $this->getTableRowUrl($row) : null"
36+
:url="method_exists($this, 'getTableRowUrl') ? $this->getTableRowUrl($row) : ''"
37+
:class="method_exists($this, 'setTableRowClass') ? ' ' . $this->setTableRowClass($row) : ''"
38+
:id="method_exists($this, 'setTableRowId') ? $this->setTableRowId($row) : ''"
39+
:customAttributes="method_exists($this, 'setTableRowAttributes') ? $this->setTableRowAttributes($row) : []"
3740
>
3841
@if (count($bulkActions))
3942
<x-livewire-tables::bs4.table.cell>
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
<td {{ $attributes }}>
1+
@props(['customAttributes' => []])
2+
3+
<td {{ $attributes->merge($customAttributes) }}>
24
{{ $slot }}
35
</td>
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
@foreach($columns as $column)
22
@if ($column->isVisible())
3-
<td>
3+
<x-livewire-tables::bs5.table.cell
4+
:class="method_exists($this, 'setTableDataClass') ? $this->setTableDataClass($column, $row) : ''"
5+
:id="method_exists($this, 'setTableDataId') ? $this->setTableDataId($column, $row) : ''"
6+
:customAttributes="method_exists($this, 'setTableDataAttributes') ? $this->setTableDataAttributes($column, $row) : []"
7+
>
48
@if ($column->asHtml)
59
{{ new \Illuminate\Support\HtmlString($column->formatted($row)) }}
610
@else
711
{{ $column->formatted($row) }}
812
@endif
9-
</td>
13+
</x-livewire-tables::bs5.table.cell>
1014
@endif
1115
@endforeach

resources/views/bootstrap-5/components/table/row.blade.php

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

33
<tr
4-
{{ $attributes }}
4+
{{ $attributes->merge($customAttributes) }}
55

66
@if ($url)
77
onclick="window.location='{{ $url }}';"

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ class="form-check-input"
3434
<x-livewire-tables::bs5.table.row
3535
wire:loading.class.delay="text-muted"
3636
wire:key="table-row-{{ $row->getKey() }}"
37-
:url="method_exists($this, 'getTableRowUrl') ? $this->getTableRowUrl($row) : null"
37+
:url="method_exists($this, 'getTableRowUrl') ? $this->getTableRowUrl($row) : ''"
38+
:class="method_exists($this, 'setTableRowClass') ? ' ' . $this->setTableRowClass($row) : ''"
39+
:id="method_exists($this, 'setTableRowId') ? $this->setTableRowId($row) : ''"
40+
:customAttributes="method_exists($this, 'setTableRowAttributes') ? $this->setTableRowAttributes($row) : []"
3841
>
3942
@if (count($bulkActions))
4043
<x-livewire-tables::bs5.table.cell class="align-middle">
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
<td {{ $attributes->merge(['class' => 'px-3 py-2 md:px-6 md:py-4 whitespace-nowrap text-sm leading-5 text-gray-900']) }}>
1+
@props(['customAttributes' => []])
2+
3+
<td {{ $attributes->merge(array_merge(['class' => 'px-3 py-2 md:px-6 md:py-4 whitespace-nowrap text-sm leading-5 text-gray-900'], $customAttributes)) }}>
24
{{ $slot }}
35
</td>

0 commit comments

Comments
 (0)