Skip to content

Commit cbccbab

Browse files
committed
Add getSlug Helper for identifying selected column
1 parent 7570e3e commit cbccbab

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ class="text-indigo-600 rounded border-gray-300 shadow-sm transition duration-150
260260
wire:target="selectedColumns"
261261
wire:loading.attr="disabled"
262262
type="checkbox"
263-
value="{{ $column->getField() }}"
263+
value="{{ $column->getSlug() }}"
264264
/>
265265
<span class="ml-2">{{ $column->getTitle() }}</span>
266266
</label>
@@ -511,7 +511,7 @@ class="px-2 {{ $loop->last ? 'mb-0' : 'mb-1' }}"
511511
wire:target="selectedColumns"
512512
wire:loading.attr="disabled"
513513
type="checkbox"
514-
value="{{ $column->getField() }}"
514+
value="{{ $column->getSlug() }}"
515515
/>
516516
<span class="ml-2">{{ $column->getTitle() }}</span>
517517
</label>

src/Traits/Helpers/ColumnSelectHelpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function rememberColumnSelectionIsDisabled(): bool
6565
*/
6666
public function columnSelectIsEnabledForColumn($column): bool
6767
{
68-
return in_array($column instanceof Column ? $column->getField() : $column, $this->selectedColumns, true);
68+
return in_array($column instanceof Column ? $column->getSlug() : $column, $this->selectedColumns, true);
6969
}
7070

7171
/**

src/Traits/WithColumnSelect.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function setupColumnSelect(): void
3131
->filter(function ($column) {
3232
return $column->isVisible() && $column->isSelectable() && $column->isSelected();
3333
})
34-
->map(fn ($column) => $column->getField())
34+
->map(fn ($column) => $column->getSlug())
3535
->values()
3636
->toArray();
3737

@@ -42,8 +42,8 @@ public function setupColumnSelect(): void
4242

4343
// Check to see if there are any excluded that are already stored in the enabled and remove them
4444
foreach ($this->getColumns() as $column) {
45-
if (! $column->isSelectable() && ! in_array($column->getField(), $this->selectedColumns, true)) {
46-
$this->selectedColumns[] = $column->getField();
45+
if (! $column->isSelectable() && ! in_array($column->getSlug(), $this->selectedColumns, true)) {
46+
$this->selectedColumns[] = $column->getSlug();
4747
session([$this->getColumnSelectSessionKey() => $this->selectedColumns]);
4848
}
4949
}

src/Views/Traits/Helpers/ColumnHelpers.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Eloquent\Model;
66
use Illuminate\Support\HtmlString;
7+
use Illuminate\Support\Str;
78
use Rappasoft\LaravelLivewireTables\DataTableComponent;
89
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
910
use Rappasoft\LaravelLivewireTables\Views\Column;
@@ -44,6 +45,14 @@ public function getTitle(): string
4445
return $this->title;
4546
}
4647

48+
/**
49+
* @return string
50+
*/
51+
public function getSlug(): string
52+
{
53+
return Str::slug($this->title);
54+
}
55+
4756
/**
4857
* @return string|null
4958
*/

0 commit comments

Comments
 (0)