Skip to content

Commit 3e6277f

Browse files
committed
Ability to define the sorting direction names for each column. i.e. A-Z, Z-A, Yes, No, Enabled, Disabled, etc.
1 parent af9ad17 commit 3e6277f

File tree

6 files changed

+19
-3
lines changed

6 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to `laravel-livewire-tables` will be documented in this file
77
### Added
88

99
- Ability to disable pagination (https://github.com/rappasoft/laravel-livewire-tables/pull/222)
10+
- Ability to define the sorting direction names for each column. i.e. A-Z, Z-A, Yes, No, Enabled, Disabled, etc.
1011

1112
### Changed
1213

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ public array $sortNames = [
229229
];
230230
```
231231

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+
232244
### Defining The Query
233245

234246
Your datatable must have a base query, which you define in the **query()** method:
@@ -404,6 +416,8 @@ There are some class level properties you can set:
404416
| $showPagination | true | bool | Show the pagination when pagination is enabled |
405417
| $showSorting | true | bool | Show the sorting pills |
406418
| $showFilters | true | bool | Show the filter pills |
419+
| $sortNames | [] | string[] | Change the sort name of the column for the sorting pill display |
420+
| $sortDirectionNames | [] | string[] | Change the direction name of the column for the sorting pill display (i.e. A-Z, Z-A) |
407421
| $perPage | 10 | int | The default per page amount selected (must exist in list) |
408422
| $perPageAccepted | [10, 25, 50] | int[] | The values for the per page dropdown, in order |
409423
| $searchFilterDebounce | null | null/int | Adds a debounce of `$searchFilterDebounce` ms to the search input |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
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/includes/sorting-pills.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
wire:key="sorting-pill-{{ $col }}"
88
class="badge rounded-pill bg-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/tailwind/includes/sorting-pills.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
wire:key="sorting-pill-{{ $col }}"
88
class="inline-flex items-center py-0.5 pl-2 pr-0.5 rounded-full text-xs font-medium bg-indigo-100 text-indigo-700"
99
>
10-
{{ $sortNames[$col] ?? ucwords(strtr($col, ['_' => ' ', '-' => ' '])) }}: {{ $dir === 'asc' ? 'A-Z' : 'Z-A' }}
10+
{{ $sortNames[$col] ?? ucwords(strtr($col, ['_' => ' ', '-' => ' '])) }}: {{ $dir === 'asc' ? ($sortDirectionNames[$col]['asc'] ?? 'A-Z') : ($sortDirectionNames[$col]['desc'] ?? 'Z-A') }}
1111

1212
<button
1313
wire:click="removeSort('{{ $col }}')"

src/Traits/WithSorting.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ trait WithSorting
1212
public bool $showSorting = true;
1313
public array $sorts = [];
1414
public array $sortNames = [];
15+
public array $sortDirectionNames = [];
1516

1617
public function sortBy(string $field): ?string
1718
{

0 commit comments

Comments
 (0)