Skip to content

Commit 6068b04

Browse files
committed
Revert "check/uncheck all selected columns"
This reverts commit 3a03091.
1 parent 3a03091 commit 6068b04

File tree

3 files changed

+9
-96
lines changed

3 files changed

+9
-96
lines changed

CHANGELOG.md

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

55
## [Unreleased]
66

7-
## [column-select-dev] - 2022-05-18
8-
9-
### Added
10-
11-
- Added functionality to select/desect all columns in column selection dropdown
12-
137
## [column-select-dev] - 2022-05-16
148

159
### Added

resources/views/components/tools/toolbar.blade.php

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -246,26 +246,6 @@ class="absolute right-0 z-50 mt-2 w-full bg-white rounded-md divide-y divide-gra
246246
>
247247
<div class="bg-white rounded-md shadow-xs dark:bg-gray-700 dark:text-white">
248248
<div class="p-2" role="menu" aria-orientation="vertical" aria-labelledby="column-select-menu">
249-
<div>
250-
<label
251-
wire:loading.attr="disabled"
252-
class="inline-flex items-center px-2 py-1 disabled:opacity-50 disabled:cursor-wait"
253-
>
254-
<input
255-
class="text-indigo-600 transition duration-150 ease-in-out border-gray-300 rounded shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600 disabled:opacity-50 disabled:cursor-wait"
256-
@if(count($component->selectedColumns) === count($component->getDefaultVisibleColumns()))
257-
checked
258-
wire:click="deselectAllColumns"
259-
@else
260-
unchecked
261-
wire:click="selectAllColumns"
262-
@endif
263-
wire:loading.attr="disabled"
264-
type="checkbox"
265-
/>
266-
<span class="ml-2">{{ __('All Columns') }}</span>
267-
</label>
268-
</div>
269249
@foreach($component->getColumns() as $column)
270250
@if ($column->isVisible() && $column->isSelectable())
271251
<div wire:key="columnSelect-{{ $loop->index }}-{{ $component->getTableName() }}">
@@ -518,25 +498,6 @@ class="dropdown-menu dropdown-menu-right w-100 mt-0 mt-md-3"
518498
x-bind:class="{'show' : open}"
519499
aria-labelledby="columnSelect-{{ $component->getTableName() }}"
520500
>
521-
<div>
522-
<label
523-
wire:loading.attr="disabled"
524-
class="mb-1"
525-
>
526-
<input
527-
@if(count($component->selectedColumns) === count($component->getDefaultVisibleColumns()))
528-
checked
529-
wire:click="deselectAllColumns"
530-
@else
531-
unchecked
532-
wire:click="selectAllColumns"
533-
@endif
534-
wire:loading.attr="disabled"
535-
type="checkbox"
536-
/>
537-
<span class="ml-2">{{ __('All Columns') }}</span>
538-
</label>
539-
</div>
540501
@foreach($component->getColumns() as $column)
541502
@if ($column->isVisible() && $column->isSelectable())
542503
<div wire:key="columnSelect-{{ $loop->index }}-{{ $component->getTableName() }}">
@@ -780,25 +741,6 @@ class="dropdown-menu dropdown-menu-end w-100"
780741
x-bind:class="{'show' : open}"
781742
aria-labelledby="columnSelect-{{ $component->getTableName() }}"
782743
>
783-
<div>
784-
<label
785-
wire:loading.attr="disabled"
786-
class="mb-1"
787-
>
788-
<input
789-
@if(count($component->selectedColumns) === count($component->getDefaultVisibleColumns()))
790-
checked
791-
wire:click="deselectAllColumns"
792-
@else
793-
unchecked
794-
wire:click="selectAllColumns"
795-
@endif
796-
wire:loading.attr="disabled"
797-
type="checkbox"
798-
/>
799-
<span class="ml-2">{{ __('All Columns') }}</span>
800-
</label>
801-
</div>
802744
@foreach($component->getColumns() as $column)
803745
@if ($column->isVisible() && $column->isSelectable())
804746
<div wire:key="columnSelect-{{ $loop->index }}-{{ $component->getTableName() }}">

src/Traits/WithColumnSelect.php

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ public function setupColumnSelect(): void
2727
}
2828

2929
// Get a list of visible default columns that are not excluded
30-
$columns = $this->getDefaultVisibleColumns();
30+
$columns = collect($this->getColumns())
31+
->filter(function ($column) {
32+
return $column->isVisible() && $column->isSelectable() && $column->isSelected();
33+
})
34+
->map(fn ($column) => $column->getSlug())
35+
->values()
36+
->toArray();
3137

3238
// Set to either the default set or what is stored in the session
3339
$this->selectedColumns = (isset($this->{$this->tableName}['columns']) && count($this->{$this->tableName}['columns']) > 0) ?
@@ -43,38 +49,9 @@ public function setupColumnSelect(): void
4349
}
4450
}
4551

46-
public function getDefaultVisibleColumns(): array
47-
{
48-
return collect($this->getColumns())
49-
->filter(function ($column) {
50-
return $column->isVisible() && $column->isSelectable() && $column->isSelected();
51-
})
52-
->map(fn ($column) => $column->getSlug())
53-
->values()
54-
->toArray();
55-
}
56-
57-
public function selectAllColumns()
58-
{
59-
$this->{$this->tableName}['columns'] = [];
60-
$this->forgetColumnSelectSession();
61-
}
62-
63-
public function deselectAllColumns()
64-
{
65-
$this->{$this->tableName}['columns'] = [];
66-
$this->selectedColumns = [];
67-
session([$this->getColumnSelectSessionKey() => []]);
68-
}
69-
7052
public function updatedSelectedColumns(): void
7153
{
72-
// The query string isn't needed if it's the same as the default
73-
if(count($this->selectedColumns) === count($this->getDefaultVisibleColumns())){
74-
$this->selectAllColumns();
75-
}else{
76-
$this->{$this->tableName}['columns'] = $this->selectedColumns;
77-
session([$this->getColumnSelectSessionKey() => $this->{$this->tableName}['columns']]);
78-
}
54+
$this->{$this->tableName}['columns'] = $this->selectedColumns;
55+
session([$this->getColumnSelectSessionKey() => $this->{$this->tableName}['columns']]);
7956
}
8057
}

0 commit comments

Comments
 (0)