Skip to content

Commit 362cd33

Browse files
committed
Changes
- Added loading message to table body if $loadingIndicator is true - Add clear button option to search box - $disableSearchOnLoading default to false - Trim the search term when processing - Existing loading subview for tbody message
1 parent d7962e7 commit 362cd33

File tree

9 files changed

+74
-24
lines changed

9 files changed

+74
-24
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
1212
- Make docblocks work with psalm
1313
- Added searching method either debounce or lazy
1414
- Allow dot notation for customer attributes
15+
- Added loading message to table body if $loadingIndicator is true
16+
- Add clear button option to search box
1517

1618
### Changed
1719

1820
- Updated Livewire to 1.3
21+
- $disableSearchOnLoading default to false
22+
- Trim the search term when processing
1923

2024
### Removed
2125

26+
- Existing loading subview for tbody message
27+
2228
## [0.1.6] - 2020-06-15
2329

2430
### Changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,13 @@ You can override any of these in your table component:
162162
| $searchEnabled | true | Whether or not searching is enabled |
163163
| $searchUpdateMethod | debounce | debounce or lazy |
164164
| $searchDebounce | 350 | Amount of time in ms to wait to send the search query and refresh the table |
165-
| $disableSearchOnLoading | true | Whether or not to disable the search bar when it is searching/loading new data |
165+
| $disableSearchOnLoading | false | Whether or not to disable the search bar when it is searching/loading new data |
166166
| $search | *none* | The initial search string |
167167
| $searchLabel | Search... | The placeholder for the search box |
168168
| $noResultsMessage | There are no results to display for this query. | The message to display when there are no results |
169+
| $clearSearchButton | false | Adds a clear button to the search input |
170+
| $clearSearchButtonClass | btn btn-outline-dark | The class applied to the clear button |
171+
| $clearSearchButtonLabel | Search | The label of the search button |
169172

170173
#### Sorting
171174

resources/views/includes/_body.blade.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
<tbody>
1+
@if ($loadingIndicator)
2+
<tbody wire:loading>
3+
<tr><td colspan="{{ collect($columns)->count() }}">{{ $loadingMessage }}</td></tr>
4+
</tbody>
5+
6+
<tbody wire:loading.remove>
7+
@else
8+
<tbody>
9+
@endif
210
@if($models->isEmpty())
311
<tr><td colspan="{{ collect($columns)->count() }}">{{ $noResultsMessage }}</td></tr>
412
@else

resources/views/includes/_loading.blade.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

resources/views/includes/_options.blade.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,23 @@
2020

2121
@if ($searchEnabled)
2222
<div class="col">
23-
<input
24-
@if (is_numeric($searchDebounce) && $searchUpdateMethod === 'debounce') wire:model.debounce.{{ $searchDebounce }}ms="search" @endif
25-
@if ($searchUpdateMethod === 'lazy') wire:model.lazy="search" @endif
26-
@if ($disableSearchOnLoading) wire:loading.attr="disabled" @endif
27-
class="form-control"
28-
type="text"
29-
placeholder="{{ $searchLabel }}"
30-
/>
23+
@if ($clearSearchButton)
24+
<div class="input-group">
25+
@endif
26+
<input
27+
@if (is_numeric($searchDebounce) && $searchUpdateMethod === 'debounce') wire:model.debounce.{{ $searchDebounce }}ms="search" @endif
28+
@if ($searchUpdateMethod === 'lazy') wire:model.lazy="search" @endif
29+
@if ($disableSearchOnLoading) wire:loading.attr="disabled" @endif
30+
class="form-control"
31+
type="text"
32+
placeholder="{{ $searchLabel }}"
33+
/>
34+
@if ($clearSearchButton)
35+
<div class="input-group-append">
36+
<button class="{{ $clearSearchButtonClass }}" type="button" wire:click="clearSearch">{{ $clearSearchButtonLabel }}</button>
37+
</div>
38+
</div>
39+
@endif
3140
</div>
3241
@endif
3342
</div>

resources/views/table-component.blade.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
@endif
88
@include('laravel-livewire-tables::includes._offline')
99
@include('laravel-livewire-tables::includes._options')
10-
@include('laravel-livewire-tables::includes._loading')
1110

1211
@if (is_string($responsive))
1312
<div class="{{ $responsive }}">

src/TableComponent.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function setTranslationStrings()
7272
$this->noResultsMessage = __('There are no results to display for this query.');
7373
$this->perPageLabel = __('Per Page');
7474
$this->searchLabel = __('Search...');
75+
$this->clearSearchButtonLabel = __('Clear');
7576
}
7677

7778
/**

src/Traits/Loading.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ trait Loading
1616
*
1717
* @var bool
1818
*/
19-
public $loadingIndicator = false;
19+
public $loadingIndicator = true;
20+
21+
/**
22+
* Whether or not to disable the search bar when it is searching/loading new data.
23+
*
24+
* @var bool
25+
*/
26+
public $disableSearchOnLoading = false;
2027

2128
/**
2229
* The loading message that gets displayed.

src/Traits/Search.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ trait Search
3232
*/
3333
public $searchDebounce = 350;
3434

35-
/**
36-
* Whether or not to disable the search bar when it is searching/loading new data.
37-
*
38-
* @var bool
39-
*/
40-
public $disableSearchOnLoading = true;
41-
4235
/**
4336
* The initial search string.
4437
*
@@ -59,4 +52,33 @@ trait Search
5952
* @var string
6053
*/
6154
public $noResultsMessage;
55+
56+
/**
57+
* A button to clear the search box
58+
*
59+
* @var bool
60+
*/
61+
public $clearSearchButton = false;
62+
63+
/**
64+
* The text for the clear search box button
65+
*
66+
* @var
67+
*/
68+
public $clearSearchButtonLabel;
69+
70+
/**
71+
* The classes to apply to the clear search box button
72+
*
73+
* @var string
74+
*/
75+
public $clearSearchButtonClass = 'btn btn-outline-dark';
76+
77+
/**
78+
* Resets the search string
79+
*/
80+
public function clearSearch() : void
81+
{
82+
$this->search = '';
83+
}
6284
}

0 commit comments

Comments
 (0)