Skip to content

Commit 91f1f2b

Browse files
authored
Merge pull request #488 from rappasoft/develop
Add secondary header
2 parents d3efe71 + 6595191 commit 91f1f2b

File tree

12 files changed

+237
-4
lines changed

12 files changed

+237
-4
lines changed

CHANGELOG.md

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

55
## [Unreleased]
66

7+
## [1.18.0] - 2021-10-13
8+
9+
### Added
10+
11+
- Secondary header (see documentation section `Secondary Header Functionality` on how to implement column search)
12+
13+
### Changed
14+
15+
- Add missing properties to reordering session
16+
717
## [1.17.0] - 2021-10-12
818

919
### Added
@@ -495,7 +505,8 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
495505

496506
- Initial release
497507

498-
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.17.0...development
508+
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.1.0...development
509+
[1.18.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.17.0...v1.18.0
499510
[1.17.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.16.0...v1.17.0
500511
[1.16.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.15.0...v1.16.0
501512
[1.15.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.14.0...v1.15.0

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ class UsersTable extends DataTableComponent
7272
- [x] Sorting By Relationships
7373
- [x] User Column Selection
7474
- [x] Drag & Drop (beta)
75+
- [x] Column Search
76+
- [x] Greater Configurability
7577
- [ ] Collection/Query Support
7678
- [ ] Test Suite (WIP)
77-
- [ ] Column Search
78-
- [ ] Greater Configurability
7979

8080
## Testing
8181

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@props(['customSecondaryHeader' => false, 'useHeaderAsFooter' => false, 'customFooter' => false])
2+
13
<div class="{{ $this->responsive ? 'table-responsive' : '' }}">
24
<table {{ $attributes->except('wire:sortable') }} class="table table-striped">
35
<thead>
@@ -7,6 +9,10 @@
79
</thead>
810

911
<tbody {{ $attributes->only('wire:sortable') }}>
12+
@if ($customSecondaryHeader)
13+
{{ $customSecondaryHead }}
14+
@endif
15+
1016
{{ $body }}
1117
</tbody>
1218

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<x-livewire-tables::bs4.table
22
wire:sortable="{{ $reordering ? $reorderingMethod : '' }}"
3+
:customSecondaryHeader="$secondaryHeader"
34
:useHeaderAsFooter="$useHeaderAsFooter"
45
:customFooter="$customFooter"
56
>
@@ -38,6 +39,47 @@
3839
@endforeach
3940
</x-slot>
4041

42+
@if ($secondaryHeader)
43+
<x-slot name="customSecondaryHead">
44+
<x-livewire-tables::bs4.table.row
45+
wire:loading.class.delay="opacity-50 dark:bg-gray-900 dark:opacity-60"
46+
:class="method_exists($this, 'setSecondaryHeaderRowClass') ? ' ' . $this->setSecondaryHeaderRowClass($rows) : ''"
47+
:id="method_exists($this, 'setSecondaryHeaderRowId') ? $this->setSecondaryHeaderRowId($rows) : ''"
48+
:customAttributes="method_exists($this, 'setSecondaryHeaderRowAttributes') ? $this->setSecondaryHeaderRowAttributes($rows) : []"
49+
>
50+
@if ($reordering)
51+
<x-livewire-tables::bs4.table.cell />
52+
@endif
53+
54+
@if ($bulkActionsEnabled && count($this->bulkActions))
55+
<x-livewire-tables::bs4.table.cell />
56+
@endif
57+
58+
@foreach($columns as $column)
59+
@if ($column->isVisible())
60+
@continue($columnSelect && ! $this->isColumnSelectEnabled($column))
61+
62+
@if ($column->hasSecondaryHeader())
63+
<x-livewire-tables::bs4.table.cell
64+
:class="method_exists($this, 'setSecondaryHeaderDataClass') ? $this->setSecondaryHeaderDataClass($column, $rows) : ''"
65+
:id="method_exists($this, 'setSecondaryHeaderDataId') ? $this->setSecondaryHeaderDataId($column, $rows) : ''"
66+
:customAttributes="method_exists($this, 'setSecondaryHeaderDataAttributes') ? $this->setSecondaryHeaderDataAttributes($column, $rows) : []"
67+
>
68+
@if ($column->isHtml())
69+
{{ new \Illuminate\Support\HtmlString($column->secondaryHeaderFormatted($rows)) }}
70+
@else
71+
{{ $column->secondaryHeaderFormatted($rows) }}
72+
@endif
73+
</x-livewire-tables::bs4.table.cell>
74+
@else
75+
<x-livewire-tables::bs4.table.cell />
76+
@endif
77+
@endif
78+
@endforeach
79+
</x-livewire-tables::bs4.table.row>
80+
</x-slot>
81+
@endif
82+
4183
<x-slot name="body">
4284
@php
4385
$colspan = count($columns);

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@props(['customSecondaryHeader' => false, 'useHeaderAsFooter' => false, 'customFooter' => false])
2+
13
<div class="{{ $this->responsive ? 'table-responsive' : '' }}">
24
<table {{ $attributes->except('wire:sortable') }} class="table table-striped">
35
<thead>
@@ -7,6 +9,10 @@
79
</thead>
810

911
<tbody {{ $attributes->only('wire:sortable') }}>
12+
@if ($customSecondaryHeader)
13+
{{ $customSecondaryHead }}
14+
@endif
15+
1016
{{ $body }}
1117
</tbody>
1218

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<x-livewire-tables::bs5.table
22
wire:sortable="{{ $reordering ? $reorderingMethod : '' }}"
3+
:customSecondaryHeader="$secondaryHeader"
34
:useHeaderAsFooter="$useHeaderAsFooter"
45
:customFooter="$customFooter"
56
>
@@ -39,6 +40,47 @@ class="form-check-input"
3940
@endforeach
4041
</x-slot>
4142

43+
@if ($secondaryHeader)
44+
<x-slot name="customSecondaryHead">
45+
<x-livewire-tables::bs5.table.row
46+
wire:loading.class.delay="opacity-50 dark:bg-gray-900 dark:opacity-60"
47+
:class="method_exists($this, 'setSecondaryHeaderRowClass') ? ' ' . $this->setSecondaryHeaderRowClass($rows) : ''"
48+
:id="method_exists($this, 'setSecondaryHeaderRowId') ? $this->setSecondaryHeaderRowId($rows) : ''"
49+
:customAttributes="method_exists($this, 'setSecondaryHeaderRowAttributes') ? $this->setSecondaryHeaderRowAttributes($rows) : []"
50+
>
51+
@if ($reordering)
52+
<x-livewire-tables::bs5.table.cell />
53+
@endif
54+
55+
@if ($bulkActionsEnabled && count($this->bulkActions))
56+
<x-livewire-tables::bs5.table.cell />
57+
@endif
58+
59+
@foreach($columns as $column)
60+
@if ($column->isVisible())
61+
@continue($columnSelect && ! $this->isColumnSelectEnabled($column))
62+
63+
@if ($column->hasSecondaryHeader())
64+
<x-livewire-tables::bs5.table.cell
65+
:class="method_exists($this, 'setSecondaryHeaderDataClass') ? $this->setSecondaryHeaderDataClass($column, $rows) : ''"
66+
:id="method_exists($this, 'setSecondaryHeaderDataId') ? $this->setSecondaryHeaderDataId($column, $rows) : ''"
67+
:customAttributes="method_exists($this, 'setSecondaryHeaderDataAttributes') ? $this->setSecondaryHeaderDataAttributes($column, $rows) : []"
68+
>
69+
@if ($column->isHtml())
70+
{{ new \Illuminate\Support\HtmlString($column->secondaryHeaderFormatted($rows)) }}
71+
@else
72+
{{ $column->secondaryHeaderFormatted($rows) }}
73+
@endif
74+
</x-livewire-tables::bs5.table.cell>
75+
@else
76+
<x-livewire-tables::bs5.table.cell />
77+
@endif
78+
@endif
79+
@endforeach
80+
</x-livewire-tables::bs5.table.row>
81+
</x-slot>
82+
@endif
83+
4284
<x-slot name="body">
4385
@php
4486
$colspan = count($columns);

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@props(['useHeaderAsFooter' => false, 'customFooter' => false])
1+
@props(['customSecondaryHeader' => false, 'useHeaderAsFooter' => false, 'customFooter' => false])
22

33
<div class="align-middle min-w-full overflow-x-auto shadow overflow-hidden rounded-none md:rounded-lg">
44
<table {{ $attributes->except('wire:sortable') }} class="min-w-full divide-y divide-gray-200 dark:divide-none">
@@ -9,6 +9,10 @@
99
</thead>
1010

1111
<tbody {{ $attributes->only('wire:sortable') }} class="bg-white divide-y divide-gray-200 dark:divide-none">
12+
@if ($customSecondaryHeader)
13+
{{ $customSecondaryHead }}
14+
@endif
15+
1216
{{ $body }}
1317
</tbody>
1418

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<x-livewire-tables::table
22
wire:sortable="{{ $reordering ? $reorderingMethod : '' }}"
3+
:customSecondaryHeader="$secondaryHeader"
34
:useHeaderAsFooter="$useHeaderAsFooter"
45
:customFooter="$customFooter"
56
>
@@ -41,6 +42,47 @@ class="rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150
4142
@endforeach
4243
</x-slot>
4344

45+
@if ($secondaryHeader)
46+
<x-slot name="customSecondaryHead">
47+
<x-livewire-tables::table.row
48+
wire:loading.class.delay="opacity-50 dark:bg-gray-900 dark:opacity-60"
49+
:class="method_exists($this, 'setSecondaryHeaderRowClass') ? ' ' . $this->setSecondaryHeaderRowClass($rows) : ''"
50+
:id="method_exists($this, 'setSecondaryHeaderRowId') ? $this->setSecondaryHeaderRowId($rows) : ''"
51+
:customAttributes="method_exists($this, 'setSecondaryHeaderRowAttributes') ? $this->setSecondaryHeaderRowAttributes($rows) : []"
52+
>
53+
@if ($reordering)
54+
<x-livewire-tables::table.cell />
55+
@endif
56+
57+
@if ($bulkActionsEnabled && count($this->bulkActions))
58+
<x-livewire-tables::table.cell />
59+
@endif
60+
61+
@foreach($columns as $column)
62+
@if ($column->isVisible())
63+
@continue($columnSelect && ! $this->isColumnSelectEnabled($column))
64+
65+
@if ($column->hasSecondaryHeader())
66+
<x-livewire-tables::table.cell
67+
:class="method_exists($this, 'setSecondaryHeaderDataClass') ? $this->setSecondaryHeaderDataClass($column, $rows) : ''"
68+
:id="method_exists($this, 'setSecondaryHeaderDataId') ? $this->setSecondaryHeaderDataId($column, $rows) : ''"
69+
:customAttributes="method_exists($this, 'setSecondaryHeaderDataAttributes') ? $this->setSecondaryHeaderDataAttributes($column, $rows) : []"
70+
>
71+
@if ($column->isHtml())
72+
{{ new \Illuminate\Support\HtmlString($column->secondaryHeaderFormatted($rows)) }}
73+
@else
74+
{{ $column->secondaryHeaderFormatted($rows) }}
75+
@endif
76+
</x-livewire-tables::table.cell>
77+
@else
78+
<x-livewire-tables::table.cell />
79+
@endif
80+
@endif
81+
@endforeach
82+
</x-livewire-tables::table.row>
83+
</x-slot>
84+
@endif
85+
4486
<x-slot name="body">
4587
@php
4688
$colspan = count($columns);

src/DataTableComponent.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Rappasoft\LaravelLivewireTables\Traits\WithCustomPagination;
1111
use Rappasoft\LaravelLivewireTables\Traits\WithFilters;
1212
use Rappasoft\LaravelLivewireTables\Traits\WithFooter;
13+
use Rappasoft\LaravelLivewireTables\Traits\WithHeader;
1314
use Rappasoft\LaravelLivewireTables\Traits\WithPerPagePagination;
1415
use Rappasoft\LaravelLivewireTables\Traits\WithReordering;
1516
use Rappasoft\LaravelLivewireTables\Traits\WithSearch;
@@ -27,6 +28,7 @@ abstract class DataTableComponent extends Component
2728
use WithCustomPagination;
2829
use WithFilters;
2930
use WithFooter;
31+
use WithHeader;
3032
use WithPerPagePagination;
3133
use WithReordering;
3234
use WithSearch;

src/Traits/WithHeader.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Traits;
4+
5+
/**
6+
* Trait WithHeader.
7+
*/
8+
trait WithHeader
9+
{
10+
public bool $secondaryHeader = false;
11+
12+
public function mountWithHeader(): void
13+
{
14+
foreach ($this->columns() as $column) {
15+
if ($column->hasSecondaryHeader()) {
16+
$this->secondaryHeader = true;
17+
}
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)