Skip to content

Commit 71658bc

Browse files
committed
BS5 drag and drop
1 parent d984494 commit 71658bc

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
@props([
22
'column',
3+
'sortingEnabled' => true,
34
'sortable' => null,
45
'direction' => null,
56
'text' => null,
67
])
78

8-
@unless ($sortable)
9+
@unless ($sortingEnabled && $sortable)
910
<th {{ $attributes->only('class') }}>
1011
{{ $text ?? $slot }}
1112
</th>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<div class="table-responsive">
2-
<table class="table table-striped">
2+
<table {{ $attributes->except('wire:sortable') }} class="table table-striped">
33
<thead>
44
<tr>
55
{{ $head }}
66
</tr>
77
</thead>
88

9-
<tbody>
9+
<tbody {{ $attributes->only('wire:sortable') }}>
1010
{{ $body }}
1111
</tbody>
1212
</table>

resources/views/bootstrap-5/datatable.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class="container-fluid p-0"
2121
<div class="d-md-flex">
2222
@include('livewire-tables::bootstrap-5.includes.search')
2323

24-
@if ($showFilterDropdown)
25-
<div class="ms-0 ms-md-3 mb-3 mb-md-0">
24+
@if ($filtersEnabled && $showFilterDropdown)
25+
<div class="{{ $showSearch ? 'ms-0 ms-md-3' : '' }} mb-3 mb-md-0">
2626
@include('livewire-tables::bootstrap-5.includes.filters')
2727
</div>
2828
@endif

resources/views/bootstrap-5/includes/bulk-select-row.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@if (count($bulkActions) && (($selectPage && $rows->total() > $rows->count()) || count($selected)))
22
<x-livewire-tables::bs5.table.row wire:key="row-message">
3-
<x-livewire-tables::bs5.table.cell colspan="{{ count($bulkActions) ? count($columns) + 1 : count($columns) }}">
3+
<x-livewire-tables::bs5.table.cell colspan="{{ $colspan }}">
44
@if (count($selected) && !$selectAll && !$selectPage)
55
<div>
66
<span>

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
<x-livewire-tables::bs5.table>
1+
<x-livewire-tables::bs5.table wire:sortable="{{ $reorderRows }}">
22
<x-slot name="head">
3+
@if (is_string($reorderRows))
4+
<x-livewire-tables::bs5.table.heading />
5+
@endif
6+
37
@if (count($bulkActions))
48
<x-livewire-tables::bs5.table.heading>
59
<input
@@ -18,6 +22,7 @@ class="form-check-input"
1822
<x-livewire-tables::bs5.table.heading />
1923
@else
2024
<x-livewire-tables::bs5.table.heading
25+
:sortingEnabled="$sortingEnabled"
2126
:sortable="$column->isSortable()"
2227
:column="$column->column()"
2328
:direction="$column->column() ? $sorts[$column->column()] ?? null : null"
@@ -30,17 +35,32 @@ class="form-check-input"
3035
</x-slot>
3136

3237
<x-slot name="body">
38+
@php
39+
$colspan = count($columns);
40+
if (count($bulkActions)) $colspan++;
41+
if (is_string($reorderRows)) $colspan++;
42+
@endphp
43+
3344
@include('livewire-tables::bootstrap-5.includes.bulk-select-row')
3445

3546
@forelse ($rows as $index => $row)
3647
<x-livewire-tables::bs5.table.row
3748
wire:loading.class.delay="text-muted"
38-
wire:key="table-row-{{ $row->getKey() }}"
49+
wire:key="table-row-{{ $row->{$primaryKey} }}"
50+
wire:sortable.item="{{ $row->{$primaryKey} }}"
3951
:url="method_exists($this, 'getTableRowUrl') ? $this->getTableRowUrl($row) : ''"
4052
:class="method_exists($this, 'setTableRowClass') ? ' ' . $this->setTableRowClass($row) : ''"
4153
:id="method_exists($this, 'setTableRowId') ? $this->setTableRowId($row) : ''"
4254
:customAttributes="method_exists($this, 'setTableRowAttributes') ? $this->setTableRowAttributes($row) : []"
4355
>
56+
@if (is_string($reorderRows))
57+
<x-livewire-tables::bs5.table.cell wire:sortable.handle>
58+
<svg xmlns="http://www.w3.org/2000/svg" style="width:1em;height:1em;" fill="none" viewBox="0 0 24 24" stroke="currentColor">
59+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
60+
</svg>
61+
</x-livewire-tables::bs5.table.cell>
62+
@endif
63+
4464
@if (count($bulkActions))
4565
<x-livewire-tables::bs5.table.cell class="align-middle">
4666
<input

0 commit comments

Comments
 (0)