Skip to content

Commit 46133d6

Browse files
authored
Merge pull request #751 from rappasoft/develop
v2.4
2 parents c76df37 + 0d8c657 commit 46133d6

33 files changed

+468
-64
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ phpunit.xml
99
psalm.xml
1010
testbench.yaml
1111
vendor
12+
output.txt

CHANGELOG.md

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

55
## [Unreleased]
66

7+
## [2.4.0] - 2022-04-30
8+
9+
### Added
10+
11+
- Added table event listeners to sort/filter/clear from other components.
12+
- Added text filter.
13+
- Added $row as second parameter to BooleanColumn `setCallback()`.
14+
- Added `setThSortButtonAttributes()` to set attributes for th sort button.
15+
- Added `setHideConfigurableAreasWhenReorderingStatus()` to hide configurable areas when reordering status which now defaults to true.
16+
17+
### Changed
18+
19+
- Rework builder to fix passed parameters in `builder()` and `columns()` methods.
20+
- Fixed possible bug with bulk actions dropdown on Tailwind when bulk actions are hidden until a selection is made.
21+
722
## [2.3.0] - 2022-04-28
823

924
### Added
@@ -618,7 +633,8 @@ Ground Up Rebuild
618633

619634
- Initial release
620635

621-
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.3.0...development
636+
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.4.0...development
637+
[2.4.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.3.0...v2.4.0
622638
[2.3.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.2.1...v2.3.0
623639
[2.2.1]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.2.0...v2.2.1
624640
[2.2.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v2.1.0...v2.2.0

docs/columns/other-column-types.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ You can override this functionality:
6565

6666
```php
6767
BooleanColumn::make('Active')
68-
->setCallback(function(string $value) {
68+
// Note: Parameter `$row` available as of v2.4
69+
->setCallback(function(string $value, $row) {
6970
// Figure out what makes $value true
7071
}),
7172
```

docs/datatable/available-methods.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,26 @@ public function configure(): void
158158
}
159159
```
160160

161+
### setThSortButtonAttributes
162+
163+
Set a list of attributes to override on the th sort button elements
164+
165+
```php
166+
public function configure(): void
167+
{
168+
// Takes a callback that gives you the current column.
169+
$this->setThSortButtonAttributes(function(Column $column) {
170+
if ($column->isField('name')) {
171+
return [
172+
'class' => 'bg-green-500',
173+
];
174+
}
175+
176+
return [];
177+
});
178+
}
179+
```
180+
161181
By default, this replaces the default classes on the th, if you would like to keep them, set the default flag to true.
162182

163183
```php

docs/datatable/configurable-areas.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,43 @@ public function configure(): void
2929

3030
**Note:** Only specify the keys you are actually implementing, otherwise you may get uneven spacing.
3131

32+
### setHideConfigurableAreasWhenReorderingStatus
33+
34+
Defaults to **true**, set whether or not configurable areas are hidden during reordering.
35+
36+
```php
37+
public function configure(): void
38+
{
39+
$this->setHideConfigurableAreasWhenReorderingStatus(true);
40+
$this->setHideConfigurableAreasWhenReorderingStatus(false);
41+
}
42+
```
43+
44+
### setHideConfigurableAreasWhenReorderingEnabled
45+
46+
Hide configurable areas when reordering.
47+
48+
```php
49+
public function configure(): void
50+
{
51+
// Shorthand for $this->setHideConfigurableAreasWhenReorderingStatus(true)
52+
$this->setHideConfigurableAreasWhenReorderingEnabled();
53+
}
54+
```
55+
56+
### setHideConfigurableAreasWhenReorderingDisabled
57+
58+
Show configurable areas when reordering.
59+
60+
```php
61+
public function configure(): void
62+
{
63+
// Shorthand for $this->setHideConfigurableAreasWhenReorderingStatus(false)
64+
$this->setHideConfigurableAreasWhenReorderingDisabled();
65+
}
66+
```
67+
68+
3269
## Example View
3370

3471
Example dropdown for the toolbar:

docs/datatable/events.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,36 @@ These are the available events on the datatable component that you can fire from
1111
$this->emit('refreshDatatable');
1212
```
1313

14-
Calls `$refresh` on the component. Good for updating from external sources or as an alternative to polling.
14+
Calls `$refresh` on the component. Good for updating from external sources or as an alternative to polling.
15+
16+
### setSort
17+
18+
You can have the table sort a specific column:
19+
20+
```php
21+
$this->emit('setSort', 'name', 'asc');
22+
```
23+
24+
### clearSorts
25+
26+
You can clear all the applied sorts:
27+
28+
```php
29+
$this->emit('clearSorts');
30+
```
31+
32+
### setFilter
33+
34+
You can have the table run a specific filter:
35+
36+
```php
37+
$this->emit('setFilter', 'status', '1');
38+
```
39+
40+
### clearFilters
41+
42+
You can have the table clear all filters:
43+
44+
```php
45+
$this->emit('clearFilters');
46+
```

docs/filters/creating-filters.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,26 @@ DateTime filters are HTML datetime-local elements and act the same as date filte
9797

9898
Make sure to look at [all available configurations](available-methods#filter-methods) on the Filter classes.
9999

100+
## Text Filters
101+
102+
Text filters are just HTML text fields.
103+
104+
```php
105+
public function filters(): array
106+
{
107+
return [
108+
TextFilter::make('Name')
109+
->config([
110+
'placeholder' => 'Search Name',
111+
'maxlength' => '25',
112+
])
113+
->filter(function(Builder $builder, string $value) {
114+
$builder->where('users.name', 'like', '%'.$value.'%');
115+
}),
116+
];
117+
}
118+
```
119+
100120
## Filter Keys
101121

102122
By default, the filter key is just the snake version of the filter name. This is used to generate the query string as well as look up the filter object in necessary places. Each filter should have a unique key.

resources/views/components/table/th.blade.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
$attributes = $attributes->merge(['wire:key' => 'header-col-'.$index.'-'.$component->id]);
66
$theme = $component->getTheme();
77
$customAttributes = $component->getThAttributes($column);
8+
$customSortButtonAttributes = $component->getThSortButtonAttributes($column);
89
$direction = $column->hasField() ? $component->getSort($column->getColumnSelectName()) : null;
910
@endphp
1011

@@ -21,7 +22,11 @@
2122
@else
2223
<button
2324
wire:click="sortBy('{{ $column->getColumnSelectName() }}')"
24-
class="flex items-center space-x-1 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider group focus:outline-none dark:text-gray-400"
25+
{{
26+
$attributes->merge($customSortButtonAttributes)
27+
->class(['flex items-center space-x-1 text-left text-xs leading-4 font-medium text-gray-500 uppercase tracking-wider group focus:outline-none dark:text-gray-400' => $customSortButtonAttributes['default'] ?? true])
28+
->except('default')
29+
}}
2530
>
2631
<span>{{ $column->getTitle() }}</span>
2732

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@php
2+
$theme = $component->getTheme();
3+
@endphp
4+
5+
@if ($theme === 'tailwind')
6+
<div class="rounded-md shadow-sm">
7+
<input
8+
wire:model.stop="{{ $component->getTableName() }}.filters.{{ $filter->getKey() }}"
9+
wire:key="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
10+
id="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
11+
type="text"
12+
@if($filter->hasConfig('placeholder')) placeholder="{{ $filter->getConfig('placeholder') }}" @endif
13+
@if($filter->hasConfig('maxlength')) maxlength="{{ $filter->getConfig('maxlength') }}" @endif
14+
class="block w-full border-gray-300 rounded-md shadow-sm transition duration-150 ease-in-out 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"
15+
/>
16+
</div>
17+
@elseif ($theme === 'bootstrap-4' || $theme === 'bootstrap-5')
18+
<div class="mb-3 mb-md-0 input-group">
19+
<input
20+
wire:model.stop="{{ $component->getTableName() }}.filters.{{ $filter->getKey() }}"
21+
wire:key="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
22+
id="{{ $component->getTableName() }}-filter-{{ $filter->getKey() }}"
23+
type="text"
24+
@if($filter->hasConfig('placeholder')) placeholder="{{ $filter->getConfig('placeholder') }}" @endif
25+
@if($filter->hasConfig('maxlength')) maxlength="{{ $filter->getConfig('maxlength') }}" @endif
26+
class="form-control"
27+
/>
28+
</div>
29+
@endif

resources/views/components/tools/toolbar.blade.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ class="w-full inline-flex items-center justify-center px-3 py-2 border border-gr
152152
@keydown.window.escape="open = false"
153153
x-on:click.away="open = false"
154154
class="relative inline-block text-left z-10 w-full md:w-auto"
155-
wire:key="bulk-actions-button-{{ $component->getTableName() }}"
156155
>
157156
<div>
158157
<span class="rounded-md shadow-sm">

0 commit comments

Comments
 (0)