Skip to content

Commit 60d60c2

Browse files
authored
Merge pull request #765 from rappasoft/develop
v2.7.0
2 parents 3e182d0 + 55ec365 commit 60d60c2

File tree

17 files changed

+534
-173
lines changed

17 files changed

+534
-173
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ phpunit.xml
99
psalm.xml
1010
testbench.yaml
1111
vendor
12-
output.txt
12+
output.txt
13+
.vscode

CHANGELOG.md

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

55
## [Unreleased]
66

7+
## [2.7.0] - 2022-05-07
8+
9+
### Added
10+
11+
- Added functionality to hide individual filters from popover and slide down views
12+
- Added functionality to hide individual filters from filter pills
13+
- Added functionality to hide individual filters from the active filter count
14+
- Added functionality to say which filters get reset by the clear button
15+
- Added functionality to set filters as secondaryHeader or footer of columns
16+
717
## [2.6.0] - 2022-05-05
818

919
### Added
@@ -659,7 +669,8 @@ Ground Up Rebuild
659669

660670
- Initial release
661671

662-
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.6.0...development
672+
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.7.0...development
673+
[2.7.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.6.0...v2.7.0
663674
[2.6.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.5.0...v2.6.0
664675
[2.5.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.4.0...v2.5.0
665676
[2.4.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.3.0...v2.4.0

docs/columns/footer.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,22 @@ Column::make('Price')
1717

1818
The footer row is enabled when ever any column calls `footer`.
1919

20-
See also [footer component configuration](../footer/available-methods).
20+
See also [footer component configuration](../footer/available-methods).
21+
22+
## Using a filter as a footer
23+
24+
As of version 2.7, you can use a filter as a footer.
25+
26+
```php
27+
// Example filter
28+
SelectFilter::make('Active')
29+
->hiddenFromAll(), // Optional, hides the filter from the menus, pills, count.
30+
31+
// You can pass a filter directly
32+
Column::make('Active')
33+
->footer($this->getFilterByKey('active')),
34+
35+
// Or use the shorthand method
36+
Column::make('Active')
37+
->footerFilter('active'), // Takes the key from the filter, which you can find in the query string when the filter is applied.
38+
```

docs/columns/secondary-header.md

Lines changed: 11 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -19,98 +19,20 @@ The secondary header row is enabled when ever any column calls `secondaryHeader`
1919

2020
See also [secondary header component configuration](../secondary-header/available-methods).
2121

22-
## Example: Adding a column search
22+
## Using a filter as a secondary header
2323

24-
Column search is not built in by default, but is easily achievable using this feature.
25-
26-
Here are the steps you need to take:
27-
28-
1. Add state to the component to track the input values
29-
2. Add the inputs to the columns using the secondaryHeader method
30-
3. Add the clause to the query based on the new state
31-
4. Optionally, add the state to the query string to preserve it on page load.
32-
33-
### 1. Add state to the component to track the input values
34-
35-
This can be called whatever you want, but you need an array to house the values of the column search fields:
36-
37-
```php
38-
public $columnSearch = [
39-
'name' => null,
40-
];
41-
```
42-
43-
### 2. Add the inputs to the columns using the secondaryHeader method
44-
45-
You can do this inline, but I'll break it out into a partial for clarity:
24+
As of version 2.7, you can use a filter as a header.
4625

4726
```php
48-
Column::make('Name')
49-
->sortable()
50-
->searchable()
51-
->asHtml()
52-
->secondaryHeader(
53-
fn() => view('tables.cells.input-search', ['field' => 'name']);
54-
),
55-
```
56-
57-
**input-search.blade.php**
58-
59-
```html
60-
<input type="text" wire:model.debounce="columnSearch.{{ $field }}" placeholder="Search {{ ucfirst($field) }}" class="block w-full border-gray-300 rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 dark:bg-gray-700 dark:text-white dark:border-gray-600 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md" />
61-
```
62-
63-
### 3. Add the clause to the query based on the new state
64-
65-
Now you need to tell the query what to do when something is typed into the search:
66-
67-
```php
68-
public function query()
69-
{
70-
return User::query()
71-
->when(
72-
$this->columnSearch['name'] ?? null,
73-
fn ($query, $name) => $query->where('name', 'like', '%' . $name . '%')
74-
);
75-
}
76-
```
77-
78-
### Extra: Add a clear button to the inputs
79-
80-
If you want the input to have a clear button when it has a value like the default search does:
81-
82-
1. Send the state to the partial
83-
84-
```php
85-
Column::make('Name')
86-
->sortable()
87-
->searchable()
88-
->asHtml()
89-
->secondaryHeader(
90-
fn() => view('tables.cells.input-search', [
91-
'field' => 'name',
92-
'columnSearch' => $this->columnSearch
93-
])
94-
),
95-
```
96-
97-
2. Copy the search field and modify:
27+
// Example filter
28+
SelectFilter::make('Active')
29+
->hiddenFromAll(), // Optional, hides the filter from the menus, pills, count.
9830

99-
```html
100-
<div class="flex rounded-md shadow-sm">
101-
<input
102-
wire:model.debounce="columnSearch.{{ $field }}"
103-
placeholder="Search {{ ucfirst($field) }}"
104-
type="text"
105-
class="block w-full border-gray-300 rounded-md shadow-sm transition duration-150 ease-in-out sm:text-sm sm:leading-5 dark:bg-gray-700 dark:text-white dark:border-gray-600 @if (isset($columnSearch[$field]) && strlen($columnSearch[$field])) rounded-none rounded-l-md focus:ring-0 focus:border-gray-300 @else focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md @endif"
106-
/>
31+
// You can pass a filter directly
32+
Column::make('Active')
33+
->secondaryHeader($this->getFilterByKey('active')),
10734

108-
@if (isset($columnSearch[$field]) && strlen($columnSearch[$field]))
109-
<span wire:click="$set('columnSearch.{{ $field }}', null)" class="inline-flex items-center px-3 text-gray-500 bg-gray-50 rounded-r-md border border-l-0 border-gray-300 cursor-pointer sm:text-sm dark:bg-gray-700 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600">
110-
<svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
111-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
112-
</svg>
113-
</span>
114-
@endif
115-
</div>
35+
// Or use the shorthand method
36+
Column::make('Active')
37+
->secondaryHeaderFilter('active'), // Takes the key from the filter, which you can find in the query string when the filter is applied.
11638
```

docs/filters/available-methods.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,51 @@ SelectFilter::make('Active')
195195

196196
Now instead of `Active: Yes` it will say `User Status: Active`
197197

198+
### hiddenFromMenus
199+
200+
Hide the filter from both the filter popover and the filter slide down.
201+
202+
```php
203+
SelectFilter::make('Active')
204+
->hiddenFromMenus()
205+
```
206+
207+
### hiddenFromPills
208+
209+
Hide the filter from the filter pills when applied.
210+
211+
```php
212+
SelectFilter::make('Active')
213+
->hiddenFromPills()
214+
```
215+
216+
### hiddenFromFilterCount
217+
218+
Hide the filter from the filter count when applied.
219+
220+
```php
221+
SelectFilter::make('Active')
222+
->hiddenFromFilterCount()
223+
```
224+
225+
### hiddenFromAll
226+
227+
Hide the filter from the menus, pills, and count.
228+
229+
```php
230+
SelectFilter::make('Active')
231+
->hiddenFromAll()
232+
```
233+
234+
### notResetByClearButton
235+
236+
By default the `clear` button will reset all filters to their defaults. You can prevent this on a specific filter by using this method.
237+
238+
```php
239+
SelectFilter::make('Active')
240+
->notResetByClearButton()
241+
```
242+
198243
### Config
199244

200245
If the filter takes any config options, you can set them with the `config` method:
@@ -205,4 +250,4 @@ If the filter takes any config options, you can set them with the `config` metho
205250
'min' => '2020-01-01',
206251
'max' => '2021-12-31',
207252
])
208-
```
253+
```

docs/start/configuration.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ return [
3636

3737
If you find that Tailwind's CSS purge is removing styles that are needed, you have to tell Tailwind to look for the table styles so it knows not to purge them.
3838

39-
In your tailwind.config.js purge configuration:
39+
In your tailwind.config.js configuration:
4040

4141
```js
42+
// V2
4243
module.exports = {
4344
mode: 'jit',
4445
purge: [
@@ -47,6 +48,15 @@ module.exports = {
4748
],
4849
...
4950
};
51+
52+
// V3
53+
module.exports = {
54+
content: [
55+
...
56+
'./vendor/rappasoft/laravel-livewire-tables/resources/views/**/*.blade.php',
57+
],
58+
...
59+
};
5060
```
5161

5262
## Alpine.js Cloak

resources/views/components/tools/filter-pills.blade.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
@if ($theme === 'tailwind')
88
<div>
9-
@if ($component->filtersAreEnabled() && $component->filterPillsAreEnabled() && $component->hasAppliedFiltersWithValues())
9+
@if ($component->filtersAreEnabled() && $component->filterPillsAreEnabled() && $component->hasAppliedVisibleFiltersForPills())
1010
<div class="mb-4 px-4 md:p-0">
1111
<small class="text-gray-700 dark:text-white">@lang('Applied Filters'):</small>
1212

@@ -16,6 +16,7 @@
1616
@endphp
1717

1818
@continue(is_null($filter))
19+
@continue($filter->isHiddenFromPills())
1920

2021
<span
2122
wire:key="{{ $component->getTableName() }}-filter-pill-{{ $filter->getKey() }}"
@@ -49,7 +50,7 @@ class="focus:outline-none active:outline-none"
4950
</div>
5051
@elseif ($theme === 'bootstrap-4')
5152
<div>
52-
@if ($component->filtersAreEnabled() && $component->filterPillsAreEnabled() && $component->hasAppliedFiltersWithValues())
53+
@if ($component->filtersAreEnabled() && $component->filterPillsAreEnabled() && $component->hasAppliedVisibleFiltersForPills())
5354
<div class="mb-3">
5455
<small>@lang('Applied Filters'):</small>
5556

@@ -59,6 +60,7 @@ class="focus:outline-none active:outline-none"
5960
@endphp
6061

6162
@continue(is_null($filter))
63+
@continue($filter->isHiddenFromPills())
6264

6365
<span
6466
wire:key="{{ $component->getTableName() }}-filter-pill-{{ $filter->getKey() }}"
@@ -91,7 +93,7 @@ class="badge badge-pill badge-light"
9193
</div>
9294
@elseif ($theme === 'bootstrap-5')
9395
<div>
94-
@if ($component->filtersAreEnabled() && $component->filterPillsAreEnabled() && $component->hasAppliedFiltersWithValues())
96+
@if ($component->filtersAreEnabled() && $component->filterPillsAreEnabled() && $component->hasAppliedVisibleFiltersForPills())
9597
<div class="mb-3">
9698
<small>@lang('Applied Filters'):</small>
9799

@@ -101,6 +103,7 @@ class="badge badge-pill badge-light"
101103
@endphp
102104

103105
@continue(is_null($filter))
106+
@continue($filter->isHiddenFromPills())
104107

105108
<span
106109
wire:key="{{ $component->getTableName() }}-filter-pill-{{ $filter->getKey() }}"

0 commit comments

Comments
 (0)