Skip to content

Commit 3ed580a

Browse files
committed
Adding first option, and fix for emptying array
1 parent b66558e commit 3ed580a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

resources/views/components/tools/filters/multi-select-dropdown.blade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
id="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
1111
class="block w-full transition duration-150 ease-in-out border-gray-300 rounded-md shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-800 dark:text-white dark:border-gray-600"
1212
>
13+
@if ($filter->getFirstOption() != "")
14+
<option @if($filter->isEmpty($this)) selected @endif value="all">{{ $filter->getFirstOption()}}</option>
15+
@endif
1316
@foreach($filter->getOptions() as $key => $value)
1417
@if (is_iterable($value))
1518
<optgroup label="{{ $key }}">
@@ -30,6 +33,9 @@ class="block w-full transition duration-150 ease-in-out border-gray-300 rounded-
3033
id="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
3134
class="{{ $theme === 'bootstrap-4' ? 'form-control' : 'form-select' }}"
3235
>
36+
@if ($filter->getFirstOption() != "")
37+
<option @if($filter->isEmpty($this)) selected @endif value="all">{{ $filter->getFirstOption()}}</option>
38+
@endif
3339
@foreach($filter->getOptions() as $key => $value)
3440
@if (is_iterable($value))
3541
<optgroup label="{{ $key }}">

src/Views/Filters/MultiSelectDropdownFilter.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class MultiSelectDropdownFilter extends Filter
99
{
1010
protected array $options = [];
11+
protected string $firstOption = "";
1112

1213
public function options(array $options = []): MultiSelectDropdownFilter
1314
{
@@ -21,6 +22,19 @@ public function getOptions(): array
2122
return $this->options;
2223
}
2324

25+
26+
public function setFirstOption(string $firstOption): MultiSelectDropdownFilter
27+
{
28+
$this->firstOption = $firstOption;
29+
30+
return $this;
31+
}
32+
33+
public function getFirstOption(): string
34+
{
35+
return $this->firstOption;
36+
}
37+
2438
public function getKeys(): array
2539
{
2640
return collect($this->getOptions())
@@ -67,7 +81,15 @@ public function getFilterPillValue($value): ?string
6781

6882
public function isEmpty($value): bool
6983
{
70-
return ! is_array($value);
84+
if (!is_array($value))
85+
{
86+
return true;
87+
}
88+
else if (in_array("all", $value))
89+
{
90+
return true;
91+
}
92+
return false;
7193
}
7294

7395
public function render(DataTableComponent $component)

0 commit comments

Comments
 (0)