Skip to content

Commit 7e586d9

Browse files
authored
Merge pull request #224 from rappasoft/develop
v1.2.0
2 parents 6b112ce + e26b957 commit 7e586d9

23 files changed

+271
-136
lines changed

CHANGELOG.md

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

55
## [Unreleased]
66

7+
## [1.2.0] - 2021-04-22
8+
9+
### Added
10+
11+
- Ability to disable pagination (https://github.com/rappasoft/laravel-livewire-tables/pull/222)
12+
- Ability to define the sorting direction names for each column. i.e. A-Z, Z-A, Yes, No, Enabled, Disabled, etc.
13+
- Added ability to define primary key of rows for bulk select
14+
- Added selectedKeys property that returns an array of the ids of the selected rows
15+
16+
### Changed
17+
18+
- Clarified where rowView looks in read me
19+
- Null the search filter when it's empty
20+
- Fill per page options from $perPageAccepted in views
21+
- Make $perPageAccepted public
22+
23+
### Removed
24+
25+
- Removed `text-secondary` class from sorting title
26+
727
## [1.1.0] - 2021-04-21
828

929
### Added
@@ -205,7 +225,8 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
205225

206226
- Initial release
207227

208-
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.1.0...development
228+
[Unreleased]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.2.0...development
229+
[1.2.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.0.4...v1.2.0
209230
[1.1.0]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.0.4...v1.1.0
210231
[1.0.4]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.0.3...v1.0.4
211232
[1.0.3]: https://github.com/rappasoft/laravel-livewire-tables/compare/v1.0.2...v1.0.3

README.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,14 @@ Column::make('Name')
110110

111111
If you would like full control over your rows without using the Column formatter, than you can define a `rowView` and return the string to the view to render the rows. The view will be passed the current $row.
112112

113+
The string is just passed to a regular Laravel `@include()` so it starts at the resources/views directory which you do not need to specify.
114+
113115
**row.blade.php**
114116

115117
```php
116118
public function rowView(): string
117119
{
120+
// Becomes /resources/views/location/to/my/row.blade.php
118121
return 'location.to.my.row.view';
119122
}
120123
```
@@ -226,6 +229,18 @@ public array $sortNames = [
226229
];
227230
```
228231

232+
#### Configuring Sort Direction Names
233+
234+
The default sort direction names are A-Z for ascending and Z-A for descending.
235+
236+
```php
237+
public array $sortDirectionNames = [
238+
'enabled' => [
239+
'asc' => 'Yes',
240+
'desc' => 'No',
241+
],
242+
];
243+
229244
### Defining The Query
230245

231246
Your datatable must have a base query, which you define in the **query()** method:
@@ -360,10 +375,16 @@ And then using it like this:
360375
}
361376
```
362377

363-
### Creating Bulk Actions
378+
### Bulk Actions
364379

365380
Bulk actions are not required, and the bulk actions box, as well as the left-hand checkboxes will be hidden if none are defined.
366381

382+
#### The primary key
383+
384+
Each row must have a primary key, it's `'id'` by default but you can override it with the `$primaryKey` property.
385+
386+
#### Defining Bulk Actions
387+
367388
To define your bulk actions, you add them to the **$bulkActions** array.
368389

369390
```php
@@ -389,17 +410,46 @@ public function exportSelected()
389410

390411
In the component you have access to `$this->selectedRowsQuery` which is a **Builder** instance of the selected rows.
391412

413+
You may also call `selectedKeys` which gives you an array of the primary keys in order they were selected:
414+
415+
**Note:** See above to setting the primary key if not `'id`.
416+
417+
```php
418+
public function exportSelected()
419+
{
420+
if (count($this->selectedKeys)) {
421+
// Do something with the selected rows
422+
dd($this->selectedKeys);
423+
424+
// => [
425+
// 1,
426+
// 2,
427+
// 3,
428+
// 4,
429+
// ]
430+
}
431+
432+
// Notify there is nothing to export
433+
}
434+
```
435+
392436
### Options
393437

394438
There are some class level properties you can set:
395439

396440
| Property | Default | Options | Usage |
397441
| -------- | ------- | ------- | ----- |
398442
| $showSearch | true | bool | Show the search box |
399-
| $showPerPage | true | bool | Show the per page selector |
400-
| $showPagination | true | bool | Show the pagination |
443+
| $paginationEnabled | true | bool | Enable pagination or fetch all records with no pagination |
444+
| $showPerPage | true | bool | Show the per page selector when pagination is enabled |
445+
| $showPagination | true | bool | Show the pagination when pagination is enabled |
401446
| $showSorting | true | bool | Show the sorting pills |
402447
| $showFilters | true | bool | Show the filter pills |
448+
| $sortNames | [] | string[] | Change the sort name of the column for the sorting pill display |
449+
| $sortDirectionNames | [] | string[] | Change the direction name of the column for the sorting pill display (i.e. A-Z, Z-A) |
450+
| $perPage | 10 | int | The default per page amount selected (must exist in list) |
451+
| $perPageAccepted | [10, 25, 50] | int[] | The values for the per page dropdown, in order |
452+
| $primaryKey | id | string | The column to pluck for bulk actions to populate the `selectedKeys` property |
403453
| $searchFilterDebounce | null | null/int | Adds a debounce of `$searchFilterDebounce` ms to the search input |
404454
| $searchFilterDefer | null | null/bool | Adds `.defer` to the search input |
405455
| $searchFilterLazy | null | null/bool | Adds `.lazy` to the search input |

resources/views/bootstrap-4/datatable.blade.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ class="container-fluid"
2727

2828
<div class="d-md-flex">
2929
@include('livewire-tables::bootstrap-4.includes.bulk-actions')
30-
31-
<div class="ml-0 ml-md-3">
32-
@include('livewire-tables::bootstrap-4.includes.per-page')
33-
</div>
30+
@include('livewire-tables::bootstrap-4.includes.per-page')
3431
</div>
3532
</div>
3633

resources/views/bootstrap-4/includes/filter-pills.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@if ($showFilters && count(array_filter($filters)) && !(count(array_filter($filters)) === 1 && isset($filters['search'])))
22
<div class="mb-3">
3-
<small class="text-secondary">@lang('Applied Filters'):</small>
3+
<small>@lang('Applied Filters'):</small>
44

55
@foreach($filters as $key => $value)
66
@if ($key !== 'search' && strlen($value))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@if ($showPagination)
1+
@if ($paginationEnabled && $showPerPage)
22
<div class="row">
33
<div class="col-12 col-md-6">
44
{{ $rows->links() }}
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
@if ($showPerPage)
2-
<select
3-
wire:model="perPage"
4-
id="perPage"
5-
class="form-control"
6-
>
7-
<option value="10">10</option>
8-
<option value="25">25</option>
9-
<option value="50">50</option>
10-
</select>
1+
@if ($paginationEnabled && $showPerPage)
2+
<div class="ml-0 ml-md-3">
3+
<select
4+
wire:model="perPage"
5+
id="perPage"
6+
class="form-control"
7+
>
8+
@foreach ($perPageAccepted as $item)
9+
<option value="{{ $item }}">{{ $item }}</option>
10+
@endforeach
11+
</select>
12+
</div>
1113
@endif

resources/views/bootstrap-4/includes/sorting-pills.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
@if ($showSorting && count($sorts))
22
<div class="mb-3">
3-
<small class="text-secondary">@lang('Applied Sorting'):</small>
3+
<small>@lang('Applied Sorting'):</small>
44

55
@foreach($sorts as $col => $dir)
66
<span
77
wire:key="sorting-pill-{{ $col }}"
88
class="badge badge-pill badge-info d-inline-flex align-items-center"
99
>
10-
<span>{{ $sortNames[$col] ?? ucwords(strtr($col, ['_' => ' ', '-' => ' '])) }}: {{ $dir === 'asc' ? 'A-Z' : 'Z-A' }}</span>
10+
<span>{{ $sortNames[$col] ?? ucwords(strtr($col, ['_' => ' ', '-' => ' '])) }}: {{ $dir === 'asc' ? ($sortDirectionNames[$col]['asc'] ?? 'A-Z') : ($sortDirectionNames[$col]['desc'] ?? 'Z-A') }}</span>
1111

1212
<a
1313
href="#"

resources/views/bootstrap-5/datatable.blade.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ class="container-fluid"
2727

2828
<div class="d-md-flex">
2929
@include('livewire-tables::bootstrap-5.includes.bulk-actions')
30-
31-
<div class="ms-0 ms-md-3">
32-
@include('livewire-tables::bootstrap-5.includes.per-page')
33-
</div>
30+
@include('livewire-tables::bootstrap-5.includes.per-page')
3431
</div>
3532
</div>
3633

resources/views/bootstrap-5/includes/filter-pills.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@if ($showFilters && count(array_filter($filters)) && !(count(array_filter($filters)) === 1 && isset($filters['search'])))
22
<div class="mb-3">
3-
<small class="text-secondary">@lang('Applied Filters'):</small>
3+
<small>@lang('Applied Filters'):</small>
44

55
@foreach($filters as $key => $value)
66
@if ($key !== 'search' && strlen($value))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@if ($showPagination)
1+
@if ($paginationEnabled && $showPerPage)
22
<div class="row">
33
<div class="col-12 col-md-6">
44
{{ $rows->links() }}

0 commit comments

Comments
 (0)