jqh 5 years ago
parent
commit
7a91fcb308
3 changed files with 26 additions and 10 deletions
  1. 8 0
      src/Grid/Concerns/HasSelector.php
  2. 12 4
      src/Grid/Tools/QuickSearch.php
  3. 6 6
      src/Grid/Tools/Selector.php

+ 8 - 0
src/Grid/Concerns/HasSelector.php

@@ -66,6 +66,14 @@ trait HasSelector
         return $this;
     }
 
+    /**
+     * @return Selector
+     */
+    public function getSelector()
+    {
+        return $this->_selector;
+    }
+
     /**
      * Render grid selector.
      *

+ 12 - 4
src/Grid/Tools/QuickSearch.php

@@ -71,6 +71,14 @@ class QuickSearch extends AbstractTool
         return $this;
     }
 
+    /**
+     * @return string
+     */
+    public function getInput()
+    {
+        return request($this->queryName);
+    }
+
     /**
      * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
      */
@@ -88,11 +96,11 @@ class QuickSearch extends AbstractTool
         ]);
 
         $vars = [
-            'action' => $request->url() . '?' . http_build_query($query),
-            'key' => $this->queryName,
-            'value' => request($this->queryName),
+            'action'      => $request->url().'?'.http_build_query($query),
+            'key'         => $this->queryName,
+            'value'       => $this->getInput(),
             'placeholder' => $this->placeholder ?: trans('admin.search'),
-            'width' => $this->width,
+            'width'       => $this->width,
         ];
 
         return view($this->view, $vars);

+ 6 - 6
src/Grid/Tools/Selector.php

@@ -32,7 +32,7 @@ class Selector
     /**
      * @var string
      */
-    protected $queryKey;
+    protected $queryName;
 
     /**
      * Selector constructor.
@@ -43,7 +43,7 @@ class Selector
         $this->request   = request();
         $this->selectors = new Collection();
 
-        $this->queryKey = $grid->getName().'_selector';
+        $this->queryName = $grid->getName().'_selector';
     }
 
     /**
@@ -118,7 +118,7 @@ class Selector
             return $this->selected;
         }
 
-        $selected = $this->request->input($this->queryKey, []);
+        $selected = $this->request->input($this->queryName, []);
         if (! is_array($selected)) {
             return [];
         }
@@ -150,7 +150,7 @@ class Selector
         $options = Arr::get($selected, $column, []);
 
         if (is_null($value)) {
-            Arr::forget($query, "{$this->queryKey}.{$column}");
+            Arr::forget($query, "{$this->queryName}.{$column}");
 
             return $this->request->fullUrlWithQuery($query);
         }
@@ -165,9 +165,9 @@ class Selector
         }
 
         if (! empty($options)) {
-            Arr::set($query, "{$this->queryKey}.{$column}", implode(',', $options));
+            Arr::set($query, "{$this->queryName}.{$column}", implode(',', $options));
         } else {
-            Arr::forget($query, "{$this->queryKey}.{$column}");
+            Arr::forget($query, "{$this->queryName}.{$column}");
         }
 
         return $this->request->fullUrlWithQuery($query);