Skip to content

Commit f280c14

Browse files
committed
Merge branch 'develop' of https://github.com/devsrv/laravel-livewire-tables into devsrv-develop
2 parents a75b15b + d33e4dc commit f280c14

File tree

7 files changed

+75
-7
lines changed

7 files changed

+75
-7
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,28 @@
66
'text' => null,
77
])
88

9+
@php
10+
$headerAttributesList = [];
11+
$headerAttributesList[] = ['class' => $attributes->get('class')];
12+
$headerAttributesList[] = $attributes->get('extraAttributes') ?? [];
13+
14+
$headerAttributes = '';
15+
collect($headerAttributesList)->each(function($item) use(&$headerAttributes) {
16+
if(count($item)) {
17+
$headerAttributes .= collect($item)->map(fn($value, $key) => $key . '="' . $value . '"')->implode(' ');
18+
}
19+
});
20+
21+
@endphp
22+
923
@unless ($sortingEnabled && $sortable)
10-
<th {{ $attributes->only('class') }}>
24+
<th {!! $headerAttributes !!}>
1125
{{ $text ?? $slot }}
1226
</th>
1327
@else
1428
<th
1529
wire:click="sortBy('{{ $column }}', '{{ $text ?? $column }}')"
16-
{{ $attributes->only('class') }}
30+
{!! $headerAttributes !!}
1731
style="cursor:pointer;"
1832
>
1933
<div class="d-flex align-items-center">

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
:direction="$column->column() ? $sorts[$column->column()] ?? null : null"
2828
:text="$column->text() ?? ''"
2929
:class="$column->class() ?? ''"
30+
:extraAttributes="$column->attributes()"
3031
/>
3132
@endif
3233
@endif

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,28 @@
66
'text' => null,
77
])
88

9+
@php
10+
$headerAttributesList = [];
11+
$headerAttributesList[] = ['class' => $attributes->get('class')];
12+
$headerAttributesList[] = $attributes->get('extraAttributes') ?? [];
13+
14+
$headerAttributes = '';
15+
collect($headerAttributesList)->each(function($item) use(&$headerAttributes) {
16+
if(count($item)) {
17+
$headerAttributes .= collect($item)->map(fn($value, $key) => $key . '="' . $value . '"')->implode(' ');
18+
}
19+
});
20+
21+
@endphp
22+
923
@unless ($sortingEnabled && $sortable)
10-
<th {{ $attributes->only('class') }}>
24+
<th {!! $headerAttributes !!}>
1125
{{ $text ?? $slot }}
1226
</th>
1327
@else
1428
<th
1529
wire:click="sortBy('{{ $column }}', '{{ $text ?? $column }}')"
16-
{{ $attributes->only('class') }}
30+
{!! $headerAttributes !!}
1731
style="cursor:pointer;"
1832
>
1933
<div class="d-flex align-items-center">

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class="form-check-input"
2828
:direction="$column->column() ? $sorts[$column->column()] ?? null : null"
2929
:text="$column->text() ?? ''"
3030
:class="$column->class() ?? ''"
31+
:extraAttributes="$column->attributes()"
3132
/>
3233
@endif
3334
@endif

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,21 @@
66
'text' => null,
77
])
88

9-
<th
10-
{{ $attributes->merge(['class' => 'px-3 py-2 md:px-6 md:py-3 bg-gray-50'])->only('class') }}
11-
>
9+
@php
10+
$headerAttributesList = [];
11+
$headerAttributesList[] = ['class' => 'px-3 py-2 md:px-6 md:py-3 bg-gray-50 ' . $attributes->get('class')];
12+
$headerAttributesList[] = $attributes->get('extraAttributes') ?? [];
13+
14+
$headerAttributes = '';
15+
collect($headerAttributesList)->each(function($item) use(&$headerAttributes) {
16+
if(count($item)) {
17+
$headerAttributes .= collect($item)->map(fn($value, $key) => $key . '="' . $value . '"')->implode(' ');
18+
}
19+
});
20+
21+
@endphp
22+
23+
<th {!! $headerAttributes !!}>
1224
@unless ($sortingEnabled && $sortable)
1325
<span class="block text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider">
1426
{{ $text ?? $slot }}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class="rounded-md shadow-sm border-gray-300 block transition duration-150 ease-i
3030
:direction="$column->column() ? $sorts[$column->column()] ?? null : null"
3131
:text="$column->text() ?? ''"
3232
:class="$column->class() ?? ''"
33+
:extraAttributes="$column->attributes()"
3334
/>
3435
@endif
3536
@endif

src/Views/Column.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class Column
1919
*/
2020
public ?string $text = null;
2121

22+
/**
23+
* @var array
24+
*/
25+
public array $attributes = [];
26+
2227
/**
2328
* @var bool
2429
*/
@@ -170,6 +175,18 @@ public function addClass(string $class): self
170175
return $this;
171176
}
172177

178+
/**
179+
* @param array $attributes
180+
*
181+
* @return $this
182+
*/
183+
public function addAttributes(array $attributes): self
184+
{
185+
$this->attributes = $attributes;
186+
187+
return $this;
188+
}
189+
173190
/**
174191
* @return Column
175192
*/
@@ -204,6 +221,14 @@ public function text(): ?string
204221
return $this->text;
205222
}
206223

224+
/**
225+
* @return array
226+
*/
227+
public function attributes(): array
228+
{
229+
return $this->attributes;
230+
}
231+
207232
/**
208233
* @param callable $callable
209234
*

0 commit comments

Comments
 (0)