Skip to content

Commit b021dc8

Browse files
committed
Merge branch 'DeltaSystems-feature-search-model-options' into develop
2 parents 7562451 + 709905c commit b021dc8

File tree

5 files changed

+69
-12
lines changed

5 files changed

+69
-12
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,18 @@ In the component you have access to `$this->selectedRowsQuery` which is a **Buil
386386

387387
There are some class level properties you can set:
388388

389-
| Property | Default | Usage |
390-
| -------- | ------- | ----- |
391-
| $showSearch | true | Show the search box |
392-
| $showPerPage | true | Show the per page selector |
393-
| $showPagination | true | Show the pagination |
394-
| $showSorting | true | Show the sorting pills |
395-
| $showFilters | true | Show the filter pills |
396-
| $refresh | false | Whether or not to refresh the table at a certain interval. false = off, int = ms, string = functionCall |
397-
| $offlineIndicator | true | Shows a red banner when there is no internet connection. |
389+
| Property | Default | Options | Usage |
390+
| -------- | ------- | ------- | ----- |
391+
| $showSearch | true | bool | Show the search box |
392+
| $showPerPage | true | bool | Show the per page selector |
393+
| $showPagination | true | bool | Show the pagination |
394+
| $showSorting | true | bool | Show the sorting pills |
395+
| $showFilters | true | bool | Show the filter pills |
396+
| $searchFilterDebounce | null | null/int | Adds a debounce of `$searchFilterDebounce` ms to the search input |
397+
| $searchFilterDefer | null | null/bool | Adds `.defer` to the search input |
398+
| $searchFilterLazy | null | null/bool | Adds `.lazy` to the search input |
399+
| $refresh | false | false/int/string | Whether or not to refresh the table at a certain interval. false = off, int = ms, string = functionCall |
400+
| $offlineIndicator | true | bool | Shows a red banner when there is no internet connection. |
398401

399402
#### Using more than one table on a page
400403

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@if ($showSearch)
22
<div class="mb-3 mb-md-0 input-group">
33
<input
4-
wire:model.debounce.250ms="filters.search"
4+
wire:model{{ $this->searchFilterOptions }}="filters.search"
55
placeholder="{{ __('Search') }}"
66
type="text"
77
class="form-control"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@if ($showSearch)
22
<div class="mb-3 mb-md-0 input-group">
33
<input
4-
wire:model.debounce.250ms="filters.search"
4+
wire:model{{ $this->searchFilterOptions }}="filters.search"
55
placeholder="{{ __('Search') }}"
66
type="text"
77
class="form-control"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@if ($showSearch)
22
<div class="flex rounded-md shadow-sm">
33
<input
4-
wire:model.debounce.250ms="filters.search"
4+
wire:model{{ $this->searchFilterOptions }}="filters.search"
55
placeholder="{{ __('Search') }}"
66
type="text"
77
class="flex-1 shadow-sm border-cool-gray-300 block w-full transition duration-150 ease-in-out sm:text-sm sm:leading-5 focus:outline-none focus:border-indigo-300 focus:shadow-outline-indigo @if (isset($filters['search']) && strlen($filters['search'])) rounded-none rounded-l-md @else rounded-md @endif"

src/Traits/WithFilters.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,66 @@
77
*/
88
trait WithFilters
99
{
10+
/**
11+
* Filter values
12+
*
13+
* @var array
14+
*/
1015
public array $filters = [];
16+
17+
/**
18+
* Map filter names
19+
*
20+
* @var array
21+
*/
1122
public array $filterNames = [];
23+
24+
/**
25+
* Default filters
26+
*
27+
* @var array|null[]
28+
*/
1229
public array $baseFilters = [
1330
'search' => null,
1431
];
1532

33+
/**
34+
* @var int|null
35+
*/
36+
public ?int $searchFilterDebounce = null;
37+
38+
/**
39+
* @var bool|null
40+
*/
41+
public ?bool $searchFilterDefer = null;
42+
43+
/**
44+
* @var bool|null
45+
*/
46+
public ?bool $searchFilterLazy = null;
47+
48+
/**
49+
* Build Livewire model options for the search input
50+
*
51+
* @return string
52+
*/
53+
public function getSearchFilterOptionsProperty(): string
54+
{
55+
if ($this->searchFilterDebounce) {
56+
return '.debounce.' . $this->searchFilterDebounce . 'ms';
57+
}
58+
59+
if ($this->searchFilterDefer) {
60+
return '.defer';
61+
}
62+
63+
if ($this->searchFilterLazy) {
64+
return '.lazy';
65+
}
66+
67+
return '';
68+
}
69+
1670
public function resetFilters(): void
1771
{
1872
$search = $this->filters['search'] ?? null;

0 commit comments

Comments
 (0)