Skip to content

Commit 7281989

Browse files
authored
Merge pull request #990 from rappasoft/develop
v2.9.0
2 parents e6069cd + f14ff55 commit 7281989

33 files changed

+602
-110
lines changed

CHANGELOG.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,32 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
44

55
## [Unreleased]
66

7+
## [2.9.0] - 2022-12-21
8+
9+
### Added
10+
11+
- Added support for optgroups in SelectFilter - https://github.com/rappasoft/laravel-livewire-tables/pull/962
12+
- Added information about applying filters on boot - https://github.com/rappasoft/laravel-livewire-tables/pull/949
13+
- Added ComponentColumn - https://github.com/rappasoft/laravel-livewire-tables/pull/827
14+
- Added ability to set the pagination mode of `standard` or `simple`
15+
16+
### Changed
17+
18+
- Fixed formatting for relational column - https://github.com/rappasoft/laravel-livewire-tables/pull/757
19+
- Fixed errors when filter does not exist - https://github.com/rappasoft/laravel-livewire-tables/pull/979
20+
- Update basic example to represent V2 requirements - https://github.com/rappasoft/laravel-livewire-tables/pull/944
21+
- Fixed responsive on bootstrap 4 & 5 - https://github.com/rappasoft/laravel-livewire-tables/pull/903
22+
- Fix for select and checkbox inputs styling with Bootstrap 5 theme - https://github.com/rappasoft/laravel-livewire-tables/pull/864
23+
724
## [2.8.0] - 2022-07-24
825

926
### Added
1027

1128
- Added functionality to bookmark or deep link column selection
1229
- Added functionality to identify different datatable components as unique in column selection
13-
- Added funcitonality to configure query string alias
14-
- Added funcitonality to configure session key for column selection (dataTableFingerprint)
15-
- Added functionality to select/desect all columns in column selection dropdown
30+
- Added functionality to configure query string alias
31+
- Added functionality to configure session key for column selection (dataTableFingerprint)
32+
- Added functionality to select/deselect all columns in column selection dropdown
1633
- Added French translation - https://github.com/rappasoft/laravel-livewire-tables/pull/816
1734
- Added Malay translation - https://github.com/rappasoft/laravel-livewire-tables/pull/821
1835
- Added Dutch translation - https://github.com/rappasoft/laravel-livewire-tables/pull/834

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,24 @@ use Rappasoft\LaravelLivewireTables\Views\Column;
4141

4242
class UsersTable extends DataTableComponent
4343
{
44-
4544
protected $model = User::class;
4645

46+
public function configure(): void
47+
{
48+
$this->setPrimaryKey('id');
49+
}
50+
4751
public function columns(): array
4852
{
4953
return [
54+
Column::make('ID', 'id')
55+
->sortable(),
5056
Column::make('Name')
51-
->sortable()
52-
->searchable(),
53-
Column::make('E-mail', 'email')
54-
->sortable()
55-
->searchable(),
56-
Column::make('Verified', 'email_verified_at')
5757
->sortable(),
5858
];
5959
}
6060
}
61+
6162
```
6263

6364
### [See advanced example](https://rappasoft.com/docs/laravel-livewire-tables/v2/examples/advanced-example)

docs/columns/other-column-types.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,28 @@ ButtonGroupColumn::make('Actions')
159159
}),
160160
]),
161161
```
162+
163+
## Component Columns
164+
165+
Component columns let you specify a component name and attributes and provides the column value to the slot.
166+
167+
```php
168+
// Before
169+
Column::make("Email", "email")
170+
->format(function ($value) {
171+
return view('components.alert')
172+
->with('attributes', new ComponentAttributeBag([
173+
'type' => Str::endsWith($value, 'example.org') ? 'success' : 'danger',
174+
'dismissible' => true,
175+
]))
176+
->with('slot', $value);
177+
}),
178+
179+
// After
180+
ComponentColumn::make('E-mail', 'email')
181+
->component('email')
182+
->attributes(fn ($value, $row, Column $column) => [
183+
'type' => Str::endsWith($value, 'example.org') ? 'success' : 'danger',
184+
'dismissible' => true,
185+
]),
186+
```

docs/examples/advanced-example.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,19 @@ class UsersTable extends DataTableComponent
171171
$builder->where('active', false);
172172
}
173173
}),
174+
SelectFilter::make('Address Group')
175+
->options([
176+
'' => 'All',
177+
AddressGroup::query()
178+
->orderBy('type')
179+
->get()
180+
->groupBy('type')
181+
->map(fn ($addressGroup) => $addressGroup->pluck('type', 'id')->filter())
182+
->toArray(),
183+
])
184+
->filter(function(Builder $builder, string $value) {
185+
$builder->where('address_groups.type', $value);
186+
}),
174187
DateFilter::make('Verified From')
175188
->config([
176189
'min' => '2020-01-01',

docs/filters/applying-filters.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ public function builder(): Builder
4141

4242
You can use the `getAppliedFilterWithValue()` method to grab the current value of the filter or null if it is not applied.
4343

44+
## Apply Filters at the Component Boot Level
45+
46+
You may wish to apply default filters i.e. current month on accessing the view in this case you can use:
47+
48+
```php
49+
public function mount() {
50+
$this->setFilter('created_after', date('Y-m-d', strtotime('now -1 month'));
51+
}
52+
```
53+
4454
### A note about integer values
4555

4656
Even if you have your values as strings, but are still using integers, you may have unexpected results when using Eloquent's `when()` method to apply your filters (if going that route).

docs/filters/creating-filters.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,34 @@ public function filters(): array
3838

3939
You should supply the first option as the default value. I.e. nothing selected, so the filter is not applied. This value should be an empty string. When this value is selected, the filter will be removed from the query and the query string.
4040

41+
### Option Groups
42+
43+
To use `<optgroup>` elements, pass a nested array of options to the select filter.
44+
45+
```php
46+
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
47+
48+
public function filters(): array
49+
{
50+
return [
51+
SelectFilter::make('Active')
52+
->options([
53+
'' => 'All',
54+
'Open' => [
55+
1 => 'Type A',
56+
2 => 'Type B',
57+
3 => 'Type C',
58+
],
59+
'Closed' => [
60+
24 => 'Type X',
61+
25 => 'Type Y',
62+
26 => 'Type Z',
63+
],
64+
]),
65+
];
66+
}
67+
```
68+
4169
## Multi-select Filters
4270

4371
Multi-select filters are a list of checkboxes. The user can select multiple options from the list. There is also an 'All' option that will select all values.

docs/pagination/available-methods.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,16 @@ public function configure(): void
159159
```
160160

161161
**Note:** The value set must be included in the `per page accepted` values.
162+
163+
## setPaginationMethod
164+
165+
Set the pagination method. By default, the table will use the `paginate` method.
166+
167+
You may specify `simplePaginate` like so:
168+
169+
```php
170+
public function configure(): void
171+
{
172+
$this->setPaginationMethod('simple');
173+
}
174+
```

resources/views/components/pagination.blade.php

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
@if ($component->paginationVisibilityIsEnabled())
1515
<div class="mt-4 px-4 md:p-0 sm:flex justify-between items-center space-y-4 sm:space-y-0">
1616
<div>
17-
@if ($component->paginationIsEnabled() && $rows->lastPage() > 1)
17+
@if ($component->paginationIsEnabled() && $component->isPaginationMethod('standard') && $rows->lastPage() > 1)
1818
<p class="paged-pagination-results text-sm text-gray-700 leading-5 dark:text-white">
1919
<span>@lang('Showing')</span>
2020
<span class="font-medium">{{ $rows->firstItem() }}</span>
@@ -24,6 +24,13 @@
2424
<span class="font-medium">{{ $rows->total() }}</span>
2525
<span>@lang('results')</span>
2626
</p>
27+
@elseif ($component->paginationIsEnabled() && $component->isPaginationMethod('simple'))
28+
<p class="paged-pagination-results text-sm text-gray-700 leading-5 dark:text-white">
29+
<span>@lang('Showing')</span>
30+
<span class="font-medium">{{ $rows->firstItem() }}</span>
31+
<span>@lang('to')</span>
32+
<span class="font-medium">{{ $rows->lastItem() }}</span>
33+
</p>
2734
@else
2835
<p class="total-pagination-results text-sm text-gray-700 leading-5 dark:text-white">
2936
@lang('Showing')
@@ -42,7 +49,7 @@
4249
@elseif ($theme === 'bootstrap-4')
4350
<div>
4451
@if ($component->paginationVisibilityIsEnabled())
45-
@if ($component->paginationIsEnabled() && $rows->lastPage() > 1)
52+
@if ($component->paginationIsEnabled() && $component->isPaginationMethod('standard') && $rows->lastPage() > 1)
4653
<div class="row mt-3">
4754
<div class="col-12 col-md-6 overflow-auto">
4855
{{ $rows->links('livewire-tables::specific.bootstrap-4.pagination') }}
@@ -58,6 +65,19 @@
5865
<span>@lang('results')</span>
5966
</div>
6067
</div>
68+
@elseif ($component->paginationIsEnabled() && $component->isPaginationMethod('simple'))
69+
<div class="row mt-3">
70+
<div class="col-12 col-md-6 overflow-auto">
71+
{{ $rows->links('livewire-tables::specific.bootstrap-4.pagination') }}
72+
</div>
73+
74+
<div class="col-12 col-md-6 text-center text-md-right text-muted">
75+
<span>@lang('Showing')</span>
76+
<strong>{{ $rows->count() ? $rows->firstItem() : 0 }}</strong>
77+
<span>@lang('to')</span>
78+
<strong>{{ $rows->count() ? $rows->lastItem() : 0 }}</strong>
79+
</div>
80+
</div>
6181
@else
6282
<div class="row mt-3">
6383
<div class="col-12 text-muted">
@@ -72,7 +92,7 @@
7292
@elseif ($theme === 'bootstrap-5')
7393
<div>
7494
@if ($component->paginationVisibilityIsEnabled())
75-
@if ($component->paginationIsEnabled() && $rows->lastPage() > 1)
95+
@if ($component->paginationIsEnabled() && $component->isPaginationMethod('standard') && $rows->lastPage() > 1)
7696
<div class="row mt-3">
7797
<div class="col-12 col-md-6 overflow-auto">
7898
{{ $rows->links('livewire-tables::specific.bootstrap-4.pagination') }}
@@ -88,6 +108,19 @@
88108
<span>@lang('results')</span>
89109
</div>
90110
</div>
111+
@elseif ($component->paginationIsEnabled() && $component->isPaginationMethod('simple'))
112+
<div class="row mt-3">
113+
<div class="col-12 col-md-6 overflow-auto">
114+
{{ $rows->links('livewire-tables::specific.bootstrap-4.pagination') }}
115+
</div>
116+
117+
<div class="col-12 col-md-6 text-center text-md-end text-muted">
118+
<span>@lang('Showing')</span>
119+
<strong>{{ $rows->count() ? $rows->firstItem() : 0 }}</strong>
120+
<span>@lang('to')</span>
121+
<strong>{{ $rows->count() ? $rows->lastItem() : 0 }}</strong>
122+
</div>
123+
</div>
91124
@else
92125
<div class="row mt-3">
93126
<div class="col-12 text-muted">
@@ -103,4 +136,4 @@
103136

104137
@if ($component->hasConfigurableAreaFor('after-pagination'))
105138
@include($component->getConfigurableAreaFor('after-pagination'), $component->getParametersForConfigurableArea('after-pagination'))
106-
@endif
139+
@endif

resources/views/components/table/td/bulk-actions.blade.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class="rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150
1818
/>
1919
</div>
2020
</x-livewire-tables::table.td.plain>
21-
@elseif ($theme === 'bootstrap-4' || $theme === 'bootstrap-5')
21+
@elseif ($theme === 'bootstrap-4')
2222
<x-livewire-tables::table.td.plain>
2323
<input
2424
wire:model="selected"
@@ -27,5 +27,17 @@ class="rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150
2727
type="checkbox"
2828
/>
2929
</x-livewire-tables::table.td.plain>
30+
@elseif ($theme === 'bootstrap-5')
31+
<x-livewire-tables::table.td.plain>
32+
<div class="form-check">
33+
<input
34+
wire:model="selected"
35+
wire:loading.attr.delay="disabled"
36+
value="{{ $row->{$this->getPrimaryKey()} }}"
37+
type="checkbox"
38+
class="form-check-input"
39+
/>
40+
</div>
41+
</x-livewire-tables::table.td.plain>
3042
@endif
3143
@endif

resources/views/components/table/td/plain.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
<td {{ $attributes
1818
->merge($customAttributes)
1919
->class(['' => $customAttributes['default'] ?? true])
20-
->class(['none d-sm-table-cell' => $column && $column->shouldCollapseOnMobile()])
21-
->class(['none d-md-table-cell' => $column && $column->shouldCollapseOnTablet()])
20+
->class(['d-none d-sm-table-cell' => $column && $column->shouldCollapseOnMobile()])
21+
->class(['d-none d-md-table-cell' => $column && $column->shouldCollapseOnTablet()])
2222
->except('default')
2323
}}>{{ $slot }}</td>
2424
@endif

0 commit comments

Comments
 (0)