@@ -11,27 +11,32 @@ trait WithColumnSelect
11
11
{
12
12
public bool $ columnSelect = false ;
13
13
public array $ columnSelectEnabled = [];
14
-
15
14
public bool $ usesSelect = false ;
15
+ public bool $ rememberColumnSelection = true ;
16
16
17
17
public function mountWithColumnSelect (): void
18
18
{
19
+ if (! $ this ->rememberColumnSelection ) {
20
+ $ this ->forgetColumnSelectSession ();
21
+ }
22
+
19
23
// If the column select is off, make sure to clear the session
20
24
if (! $ this ->columnSelect && session ()->has ($ this ->getColumnSelectSessionKey ())) {
21
25
session ()->forget ($ this ->getColumnSelectSessionKey ());
22
26
}
23
27
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
+ }
28
32
29
33
// Get a list of visible default columns that are not excluded
30
34
$ columns = collect ($ this ->columns ())
31
35
->filter (function ($ column ) {
32
36
if ($ this ->usesSelect ) {
33
37
return $ column ->isVisible () && $ column ->isSelectable () && $ column ->isSelected ();
34
38
}
39
+
35
40
return $ column ->isVisible () && $ column ->isSelectable ();
36
41
})
37
42
->map (fn ($ column ) => $ column ->column ())
@@ -60,6 +65,11 @@ public function isColumnSelectEnabled($column): bool
60
65
return in_array ($ column instanceof Column ? $ column ->column () : $ column , $ this ->columnSelectEnabled , true );
61
66
}
62
67
68
+ private function forgetColumnSelectSession (): void
69
+ {
70
+ session ()->forget ($ this ->getColumnSelectSessionKey ());
71
+ }
72
+
63
73
private function getColumnSelectSessionKey (): string
64
74
{
65
75
return $ this ->tableName .'-columnSelectEnabled ' ;
0 commit comments