Skip to content

Commit 7829f0e

Browse files
authored
Merge pull request #261 from rappasoft/develop
v1.5.0
2 parents fd98bfc + ab61d76 commit 7829f0e

File tree

8 files changed

+169
-76
lines changed

8 files changed

+169
-76
lines changed

CHANGELOG.md

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

55
## [Unreleased]
66

7+
## [1.5.0] - 2021-05-02
8+
9+
### Added
10+
11+
- Added hideIf for columns to hide a column with a conditional, works out of the box for cells not using rowView, if using rowView you must wrap the cells you want to hide in the same conditional. [See documentation](https://github.com/rappasoft/laravel-livewire-tables/wiki/Conditionally-hiding-columns).
12+
- Added selected row de-selector when not selecting full page or all.
13+
714
## [1.4.0] - 2021-04-29
815

916
### Added
@@ -279,7 +286,8 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
279286

280287
- Initial release
281288

282-
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.4.0...development
289+
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.5.0...development
290+
[1.5.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.4.0...v1.5.0
283291
[1.4.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.3.1...v1.4.0
284292
[1.3.1]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.3.0...v1.3.1
285293
[1.3.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.2.2...v1.3.0
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
@foreach($columns as $column)
2-
<td>
3-
@if ($column->asHtml)
4-
{{ new \Illuminate\Support\HtmlString($column->formatted($row)) }}
5-
@else
6-
{{ $column->formatted($row) }}
7-
@endif
8-
</td>
2+
@if ($column->isVisible())
3+
<td>
4+
@if ($column->asHtml)
5+
{{ new \Illuminate\Support\HtmlString($column->formatted($row)) }}
6+
@else
7+
{{ $column->formatted($row) }}
8+
@endif
9+
</td>
10+
@endif
911
@endforeach

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

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,43 @@
1010
@endif
1111

1212
@foreach($columns as $column)
13-
@if ($column->isBlank())
14-
<x-livewire-tables::bs4.table.heading />
15-
@else
16-
<x-livewire-tables::bs4.table.heading
17-
:sortable="$column->isSortable()"
18-
:column="$column->column()"
19-
:direction="$column->column() ? $sorts[$column->column()] ?? null : null"
20-
:text="$column->text() ?? ''"
21-
:class="$column->class() ?? ''"
22-
/>
13+
@if ($column->isVisible())
14+
@if ($column->isBlank())
15+
<x-livewire-tables::bs4.table.heading />
16+
@else
17+
<x-livewire-tables::bs4.table.heading
18+
:sortable="$column->isSortable()"
19+
:column="$column->column()"
20+
:direction="$column->column() ? $sorts[$column->column()] ?? null : null"
21+
:text="$column->text() ?? ''"
22+
:class="$column->class() ?? ''"
23+
/>
24+
@endif
2325
@endif
2426
@endforeach
2527
</x-slot>
2628

2729
<x-slot name="body">
28-
@if (count($bulkActions) && $selectPage && $rows->total() > $rows->count())
30+
@if (count($bulkActions) && (($selectPage && $rows->total() > $rows->count()) || count($selected)))
2931
<x-livewire-tables::bs4.table.row wire:key="row-message">
3032
<x-livewire-tables::bs4.table.cell colspan="{{ count($bulkActions) ? count($columns) + 1 : count($columns) }}">
31-
@unless ($selectAll)
33+
@if (count($selected) && !$selectAll && !$selectPage)
3234
<div>
3335
<span>
3436
@lang('You have selected')
35-
<strong>{{ $rows->count() }}</strong>
36-
@lang('rows, do you want to select all')
37-
<strong>{{ number_format($rows->total()) }}</strong>?
37+
<strong>{{ count($selected) }}</strong>
38+
@lang(':rows', ['rows' => count($selected) === 1 ? 'row' : 'rows']).
3839
</span>
3940

4041
<button
41-
wire:click="selectAll"
42+
wire:click="resetBulk"
4243
type="button"
4344
class="btn btn-primary btn-sm"
4445
>
45-
@lang('Select All')
46+
@lang('Unselect All')
4647
</button>
4748
</div>
48-
@else
49+
@elseif ($selectAll)
4950
<div>
5051
<span>
5152
@lang('You are currently selecting all')
@@ -61,6 +62,23 @@ class="btn btn-primary btn-sm"
6162
@lang('Unselect All')
6263
</button>
6364
</div>
65+
@else
66+
<div>
67+
<span>
68+
@lang('You have selected')
69+
<strong>{{ $rows->count() }}</strong>
70+
@lang('rows, do you want to select all')
71+
<strong>{{ number_format($rows->total()) }}</strong>?
72+
</span>
73+
74+
<button
75+
wire:click="selectAll"
76+
type="button"
77+
class="btn btn-primary btn-sm"
78+
>
79+
@lang('Select All')
80+
</button>
81+
</div>
6482
@endif
6583
</x-livewire-tables::bs4.table.cell>
6684
</x-livewire-tables::bs4.table.row>
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
@foreach($columns as $column)
2-
<td>
3-
@if ($column->asHtml)
4-
{{ new \Illuminate\Support\HtmlString($column->formatted($row)) }}
5-
@else
6-
{{ $column->formatted($row) }}
7-
@endif
8-
</td>
2+
@if ($column->isVisible())
3+
<td>
4+
@if ($column->asHtml)
5+
{{ new \Illuminate\Support\HtmlString($column->formatted($row)) }}
6+
@else
7+
{{ $column->formatted($row) }}
8+
@endif
9+
</td>
10+
@endif
911
@endforeach

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

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,43 @@ class="form-check-input"
1111
@endif
1212

1313
@foreach($columns as $column)
14-
@if ($column->isBlank())
15-
<x-livewire-tables::bs5.table.heading />
16-
@else
17-
<x-livewire-tables::bs5.table.heading
18-
:sortable="$column->isSortable()"
19-
:column="$column->column()"
20-
:direction="$column->column() ? $sorts[$column->column()] ?? null : null"
21-
:text="$column->text() ?? ''"
22-
:class="$column->class() ?? ''"
23-
/>
14+
@if ($column->isVisible())
15+
@if ($column->isBlank())
16+
<x-livewire-tables::bs5.table.heading />
17+
@else
18+
<x-livewire-tables::bs5.table.heading
19+
:sortable="$column->isSortable()"
20+
:column="$column->column()"
21+
:direction="$column->column() ? $sorts[$column->column()] ?? null : null"
22+
:text="$column->text() ?? ''"
23+
:class="$column->class() ?? ''"
24+
/>
25+
@endif
2426
@endif
2527
@endforeach
2628
</x-slot>
2729

2830
<x-slot name="body">
29-
@if (count($bulkActions) && $selectPage && $rows->total() > $rows->count())
31+
@if (count($bulkActions) && (($selectPage && $rows->total() > $rows->count()) || count($selected)))
3032
<x-livewire-tables::bs5.table.row wire:key="row-message">
3133
<x-livewire-tables::bs5.table.cell colspan="{{ count($bulkActions) ? count($columns) + 1 : count($columns) }}">
32-
@unless ($selectAll)
34+
@if (count($selected) && !$selectAll && !$selectPage)
3335
<div>
3436
<span>
3537
@lang('You have selected')
36-
<strong>{{ $rows->count() }}</strong>
37-
@lang('rows, do you want to select all')
38-
<strong>{{ number_format($rows->total()) }}</strong>?
38+
<strong>{{ count($selected) }}</strong>
39+
@lang(':rows', ['rows' => count($selected) === 1 ? 'row' : 'rows']).
3940
</span>
4041

4142
<button
42-
wire:click="selectAll"
43+
wire:click="resetBulk"
4344
type="button"
4445
class="btn btn-primary btn-sm"
4546
>
46-
@lang('Select All')
47+
@lang('Unselect All')
4748
</button>
4849
</div>
49-
@else
50+
@elseif ($selectAll)
5051
<div>
5152
<span>
5253
@lang('You are currently selecting all')
@@ -62,6 +63,23 @@ class="btn btn-primary btn-sm"
6263
@lang('Unselect All')
6364
</button>
6465
</div>
66+
@else
67+
<div>
68+
<span>
69+
@lang('You have selected')
70+
<strong>{{ $rows->count() }}</strong>
71+
@lang('rows, do you want to select all')
72+
<strong>{{ number_format($rows->total()) }}</strong>?
73+
</span>
74+
75+
<button
76+
wire:click="selectAll"
77+
type="button"
78+
class="btn btn-primary btn-sm"
79+
>
80+
@lang('Select All')
81+
</button>
82+
</div>
6583
@endif
6684
</x-livewire-tables::bs5.table.cell>
6785
</x-livewire-tables::bs5.table.row>
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
@foreach($columns as $column)
2-
<x-livewire-tables::table.cell>
3-
@if ($column->asHtml)
4-
{{ new \Illuminate\Support\HtmlString($column->formatted($row)) }}
5-
@else
6-
{{ $column->formatted($row) }}
7-
@endif
8-
</x-livewire-tables::table.cell>
2+
@if ($column->isVisible())
3+
<x-livewire-tables::table.cell>
4+
@if ($column->asHtml)
5+
{{ new \Illuminate\Support\HtmlString($column->formatted($row)) }}
6+
@else
7+
{{ $column->formatted($row) }}
8+
@endif
9+
</x-livewire-tables::table.cell>
10+
@endif
911
@endforeach

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

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,43 @@ class="rounded-md shadow-sm border-gray-300 block transition duration-150 ease-i
1313
@endif
1414

1515
@foreach($columns as $column)
16-
@if ($column->isBlank())
17-
<x-livewire-tables::table.heading />
18-
@else
19-
<x-livewire-tables::table.heading
20-
:sortable="$column->isSortable()"
21-
:column="$column->column()"
22-
:direction="$column->column() ? $sorts[$column->column()] ?? null : null"
23-
:text="$column->text() ?? ''"
24-
:class="$column->class() ?? ''"
25-
/>
16+
@if ($column->isVisible())
17+
@if ($column->isBlank())
18+
<x-livewire-tables::table.heading />
19+
@else
20+
<x-livewire-tables::table.heading
21+
:sortable="$column->isSortable()"
22+
:column="$column->column()"
23+
:direction="$column->column() ? $sorts[$column->column()] ?? null : null"
24+
:text="$column->text() ?? ''"
25+
:class="$column->class() ?? ''"
26+
/>
27+
@endif
2628
@endif
2729
@endforeach
2830
</x-slot>
2931

3032
<x-slot name="body">
31-
@if (count($bulkActions) && $selectPage && $rows->total() > $rows->count())
33+
@if (count($bulkActions) && (($selectPage && $rows->total() > $rows->count()) || count($selected)))
3234
<x-livewire-tables::table.row wire:key="row-message" class="bg-indigo-50">
3335
<x-livewire-tables::table.cell :colspan="count($bulkActions) ? count($columns) + 1 : count($columns)">
34-
@unless ($selectAll)
36+
@if (count($selected) && !$selectAll && !$selectPage)
3537
<div>
3638
<span>
3739
@lang('You have selected')
38-
<strong>{{ $rows->count() }}</strong>
39-
@lang('rows, do you want to select all')
40-
<strong>{{ number_format($rows->total()) }}</strong>?
40+
<strong>{{ count($selected) }}</strong>
41+
@lang(':rows', ['rows' => count($selected) === 1 ? 'row' : 'rows']).
4142
</span>
4243

4344
<button
44-
wire:click="selectAll"
45+
wire:click="resetBulk"
4546
type="button"
4647
class="ml-1 text-blue-600 underline text-gray-700 text-sm leading-5 font-medium focus:outline-none focus:text-gray-800 focus:underline transition duration-150 ease-in-out"
4748
>
48-
@lang('Select All')
49+
@lang('Unselect All')
4950
</button>
5051
</div>
51-
@else
52+
@elseif ($selectAll)
5253
<div>
5354
<span>
5455
@lang('You are currently selecting all')
@@ -64,6 +65,23 @@ class="ml-1 text-blue-600 underline text-gray-700 text-sm leading-5 font-medium
6465
@lang('Unselect All')
6566
</button>
6667
</div>
68+
@else
69+
<div>
70+
<span>
71+
@lang('You have selected')
72+
<strong>{{ $rows->count() }}</strong>
73+
@lang('rows, do you want to select all')
74+
<strong>{{ number_format($rows->total()) }}</strong>?
75+
</span>
76+
77+
<button
78+
wire:click="selectAll"
79+
type="button"
80+
class="ml-1 text-blue-600 underline text-gray-700 text-sm leading-5 font-medium focus:outline-none focus:text-gray-800 focus:underline transition duration-150 ease-in-out"
81+
>
82+
@lang('Select All')
83+
</button>
84+
</div>
6785
@endif
6886
</x-livewire-tables::table.cell>
6987
</x-livewire-tables::table.row>

src/Views/Column.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ class Column
5959
*/
6060
public bool $asHtml = false;
6161

62+
/**
63+
* @var bool
64+
*/
65+
public bool $hidden = false;
66+
6267
/**
6368
* Column constructor.
6469
*
@@ -262,4 +267,24 @@ public function getSearchCallback(): ?callable
262267
{
263268
return $this->searchCallback;
264269
}
270+
271+
/**
272+
* @param $condition
273+
*
274+
* @return $this
275+
*/
276+
public function hideIf($condition): self
277+
{
278+
$this->hidden = $condition;
279+
280+
return $this;
281+
}
282+
283+
/**
284+
* @return bool
285+
*/
286+
public function isVisible(): bool
287+
{
288+
return $this->hidden !== true;
289+
}
265290
}

0 commit comments

Comments
 (0)