Skip to content

Commit 56f04ab

Browse files
committed
Fixes
1 parent 4f1c076 commit 56f04ab

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/Traits/WithColumnSelect.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,32 @@ trait WithColumnSelect
1111
{
1212
public bool $columnSelect = false;
1313
public array $columnSelectEnabled = [];
14-
1514
public bool $usesSelect = false;
15+
public bool $rememberColumnSelection = true;
1616

1717
public function mountWithColumnSelect(): void
1818
{
19+
if (! $this->rememberColumnSelection) {
20+
$this->forgetColumnSelectSession();
21+
}
22+
1923
// If the column select is off, make sure to clear the session
2024
if (! $this->columnSelect && session()->has($this->getColumnSelectSessionKey())) {
2125
session()->forget($this->getColumnSelectSessionKey());
2226
}
2327

24-
$selected = collect($this->columns())
25-
->filter(fn ($column) => $column->isSelected())->count();
26-
27-
if ($selected > 0) $this->usesSelect = true;
28+
// If any of the columns are user selected
29+
if (collect($this->columns())->filter(fn ($column) => $column->isSelected())->count() > 0) {
30+
$this->usesSelect = true;
31+
}
2832

2933
// Get a list of visible default columns that are not excluded
3034
$columns = collect($this->columns())
3135
->filter(function ($column) {
3236
if ($this->usesSelect) {
3337
return $column->isVisible() && $column->isSelectable() && $column->isSelected();
3438
}
39+
3540
return $column->isVisible() && $column->isSelectable();
3641
})
3742
->map(fn ($column) => $column->column())
@@ -60,6 +65,11 @@ public function isColumnSelectEnabled($column): bool
6065
return in_array($column instanceof Column ? $column->column() : $column, $this->columnSelectEnabled, true);
6166
}
6267

68+
private function forgetColumnSelectSession(): void
69+
{
70+
session()->forget($this->getColumnSelectSessionKey());
71+
}
72+
6373
private function getColumnSelectSessionKey(): string
6474
{
6575
return $this->tableName.'-columnSelectEnabled';

0 commit comments

Comments
 (0)