Skip to content

Commit

Permalink
Merge branch 'feature/select-all-in-multiselect-filter' of https://gi…
Browse files Browse the repository at this point in the history
…thub.com/juliomotol/laravel-livewire-tables into juliomotol-feature/select-all-in-multiselect-filter
  • Loading branch information
rappasoft committed Nov 19, 2021
2 parents 1b97c5c + a43d96d commit 0242a4e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
<div class="form-check">
<input
class="form-check-input"
onclick="event.stopPropagation();"
type="checkbox"
id="filter-{{$key}}-select-all"
wire:input="selectAllFilters('{{ $key }}')"
{{ count($filters[$key]) === count($filter->options()) ? 'checked' : ''}}
>
<label class="form-check-label" for="filter-{{$key}}-select-all">@lang('All')</label>
</div>
@foreach($filter->options() as $optionKey => $value)
<div class="form-check" wire:key="filter-{{ $key }}-multiselect-{{ $optionKey }}">
<input
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<div class="form-check">
<input
onclick="event.stopPropagation();"
type="checkbox"
id="filter-{{$key}}-select-all"
wire:input="selectAllFilters('{{ $key }}')"
{{ count($filters[$key]) === count($filter->options()) ? 'checked' : ''}}
>
<label class="form-check-label" for="filter-{{$key}}-select-all">@lang('All')</label>
</div>
@foreach($filter->options() as $optionKey => $value)
<div class="form-check" wire:key="filter-{{ $key }}-multiselect-{{ $optionKey }}">
<input
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<div class="mt-1 relative rounded-md">
<div>
<input
type="checkbox"
id="filter-{{$key}}-select-all"
wire:input="selectAllFilters('{{ $key }}')"
{{ count($filters[$key]) === count($filter->options()) ? 'checked' : ''}}
>
<label for="filter-{{$key}}-select-all">@lang('All')</label>
</div>
@foreach($filter->options() as $optionKey => $value)
<div wire:key="filter-{{ $key }}-multiselect-{{ $optionKey }}">
<input
Expand Down
16 changes: 16 additions & 0 deletions src/Traits/WithFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,22 @@ public function cleanFilters(): void
})->toArray();
}

public function selectAllFilters($filterKey): void
{
$filter = $this->filters()[$filterKey];

if (! $filter->isMultiSelect()) {
return;
}

if (count($this->filters[$filterKey]) === count($filter->options())) {
$this->removeFilter($filterKey);
return;
}

$this->filters[$filterKey] = array_keys($filter->options());
}

/**
* Define the string location to a view to be included as the filters view
*
Expand Down

0 comments on commit 0242a4e

Please sign in to comment.