22
33namespace  Rappasoft \LaravelLivewireTables \Features \ColumnSelect \Helpers ;
44
5- use  Illuminate \Support \Collection ;
65use  Livewire \Attributes \Computed ;
76use  Rappasoft \LaravelLivewireTables \Events \ColumnsSelected ;
87use  Rappasoft \LaravelLivewireTables \Features \Columns \Views \Column ;
@@ -19,7 +18,7 @@ trait ColumnSelectHelpers
1918     */ 
2019    public  function  columnSelectIsEnabledForColumn (mixed  $ columnbool 
2120    {
22-         return  in_array ($ columninstanceof  Column ? $ columngetSlug () : $ column$ this selectedColumns  ?? [], true );
21+         return  ! empty ( $ this -> selectedColumns ) &&  in_array ($ columninstanceof  Column ? $ columngetSlug () : $ column$ this selectedColumns  ?? [], true );
2322    }
2423
2524
@@ -76,7 +75,7 @@ public function getSelectableColumns(): ColumnCollection
7675        return  $ this getColumns ()
7776            ->visible ()
7877            ->selectable ()
79-             ->reject ( fn  ( Column   $ column ) =>  $ this currentlyReorderingIsEnabled () && ! $ column -> isVisibleOnReorder ())
78+             ->rejectInvisibleWhileReordering ( $ this currentlyReorderingIsEnabled ())
8079            ->values ();
8180    }
8281
@@ -92,7 +91,7 @@ public function getSelectableSelectedColumns(): ColumnCollection
9291            ->visible ()
9392            ->selectable ()
9493            ->reject (fn  (Column $ columnin_array ($ columngetSlug (), $ this selectedColumns  ?? []))
95-             ->reject ( fn  ( Column   $ column ) =>  $ this currentlyReorderingIsEnabled () && ! $ column -> isVisibleOnReorder ())
94+             ->rejectInvisibleWhileReordering ( $ this currentlyReorderingIsEnabled ())
9695            ->values ();
9796    }
9897
@@ -106,7 +105,7 @@ public function getUnSelectableColumns(): ColumnCollection
106105        return  $ this getColumns ()
107106            ->visible ()
108107            ->unselectable ()
109-             ->reject ( fn  ( Column   $ column ) =>  $ this currentlyReorderingIsEnabled () && ! $ column -> isVisibleOnReorder ())
108+             ->rejectInvisibleWhileReordering ( $ this currentlyReorderingIsEnabled ())
110109            ->values ();
111110    }
112111
@@ -131,7 +130,7 @@ public function getSelectedColumnsForQuery(): array
131130            ->visible ()
132131            ->reject (fn  (Column $ column$ columnisLabel ())
133132            ->reject (fn  (Column $ column$ columnisSelectable () && ! $ this columnSelectIsEnabledForColumn ($ column
134-             ->reject ( fn  ( Column   $ column ) =>  $ this currentlyReorderingIsEnabled () && ! $ column -> isVisibleOnReorder ())
133+             ->rejectInvisibleWhileReordering ( $ this currentlyReorderingIsEnabled ())
135134            ->values ()
136135            ->toArray ();
137136    }
@@ -146,8 +145,8 @@ public function getColumnsForColumnSelect(): array
146145        return  $ this getColumns ()
147146            ->visible ()
148147            ->selectable ()
149-             ->reject (fn  (Column $ column$ this columnSelectIsEnabledForColumn ($ column
150-             ->reject ( fn  ( Column   $ column ) =>  $ this currentlyReorderingIsEnabled () && ! $ column -> isVisibleOnReorder ())
148+             ->reject (fn  (Column $ column$ column -> isSelectable () || !  $ this columnSelectIsEnabledForColumn ($ column
149+             ->rejectInvisibleWhileReordering ( $ this currentlyReorderingIsEnabled ())
151150            ->keyBy (function  (Column $ columnint  $ key
152151                return  $ columngetSlug ();
153152            })
@@ -172,7 +171,7 @@ public function getDefaultVisibleColumns(): array
172171            ->visible ()
173172            ->reject (fn  (Column $ column$ columnisSelectable () && ! $ columnisSelected ())
174173            ->reject (fn  (Column $ column$ columnisSelectable ())
175-             ->reject ( fn  ( Column   $ column ) =>  $ this currentlyReorderingIsEnabled () && ! $ column -> isVisibleOnReorder ())
174+             ->rejectInvisibleWhileReordering ( $ this currentlyReorderingIsEnabled ())
176175            ->map (fn  ($ column$ columngetSlug ())
177176            ->values ()
178177            ->toArray ();
@@ -199,7 +198,7 @@ public function selectedVisibleColumns(): array
199198        return  $ this getColumns ()
200199            ->visible ()
201200            ->reject (fn  (Column $ column$ columnisSelectable () && ! $ this columnSelectIsEnabledForColumn ($ column
202-             ->reject ( fn  ( Column   $ column ) =>  $ this currentlyReorderingIsEnabled () && ! $ column -> isVisibleOnReorder ())
201+             ->rejectInvisibleWhileReordering ( $ this currentlyReorderingIsEnabled ())
203202            ->values ()
204203            ->toArray ();
205204    }
@@ -215,6 +214,7 @@ public function selectAllColumns(): void
215214        foreach  ($ this getSelectableColumns () as  $ column
216215            $ this selectedColumns [] = $ columngetSlug ();
217216        }
217+         $ this pushToQueryString ($ this selectedColumns );
218218        $ this storeColumnSelectValues ();
219219
220220        if  ($ this getEventStatusColumnSelect ()) {
@@ -230,6 +230,7 @@ public function selectAllColumns(): void
230230    public  function  deselectAllColumns (): void 
231231    {
232232        $ this selectedColumns  = [];
233+         $ this pushToQueryString ($ this selectedColumns );
233234        session ([$ this getColumnSelectSessionKey () => []]);
234235        if  ($ this getEventStatusColumnSelect ()) {
235236            event (new  ColumnsSelected ($ this getTableName (), $ this getColumnSelectSessionKey (), $ this selectedColumns ));
@@ -345,5 +346,4 @@ public function getColumnSelectDelay(): int
345346        return  $ this columnSelectDelay  ?? 1500 ;
346347    }
347348
348- 
349349}
0 commit comments