File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -12,16 +12,28 @@ trait WithColumnSelect
12
12
public bool $ columnSelect = false ;
13
13
public array $ columnSelectEnabled = [];
14
14
15
+ public bool $ usesSelect = false ;
16
+
15
17
public function mountWithColumnSelect (): void
16
18
{
17
19
// If the column select is off, make sure to clear the session
18
20
if (! $ this ->columnSelect && session ()->has ($ this ->getColumnSelectSessionKey ())) {
19
21
session ()->forget ($ this ->getColumnSelectSessionKey ());
20
22
}
21
23
24
+ $ selected = collect ($ this ->columns ())
25
+ ->filter (fn ($ column ) => $ column ->isSelected ())->count ();
26
+
27
+ if ($ selected > 0 ) $ this ->usesSelect = true ;
28
+
22
29
// Get a list of visible default columns that are not excluded
23
30
$ columns = collect ($ this ->columns ())
24
- ->filter (fn ($ column ) => $ column ->isVisible () && $ column ->isSelectable ())
31
+ ->filter (function ($ column ) {
32
+ if ($ this ->usesSelect ) {
33
+ return $ column ->isVisible () && $ column ->isSelectable () && $ column ->isSelected ();
34
+ }
35
+ return $ column ->isVisible () && $ column ->isSelectable ();
36
+ })
25
37
->map (fn ($ column ) => $ column ->column ())
26
38
->values ()
27
39
->toArray ();
Original file line number Diff line number Diff line change @@ -74,6 +74,11 @@ class Column
74
74
*/
75
75
public bool $ selectable = true ;
76
76
77
+ /**
78
+ * @var bool
79
+ */
80
+ public bool $ selected = false ;
81
+
77
82
/**
78
83
* Column constructor.
79
84
*
@@ -335,4 +340,22 @@ public function isSelectable(): bool
335
340
{
336
341
return $ this ->selectable === true ;
337
342
}
343
+
344
+ /**
345
+ * @return $this
346
+ */
347
+ public function selected (): self
348
+ {
349
+ $ this ->selected = true ;
350
+
351
+ return $ this ;
352
+ }
353
+
354
+ /**
355
+ * @return bool
356
+ */
357
+ public function isSelected (): bool
358
+ {
359
+ return $ this ->selected ;
360
+ }
338
361
}
You can’t perform that action at this time.
0 commit comments