jqh 4 years ago
parent
commit
190c3a529e
2 changed files with 29 additions and 5 deletions
  1. 2 1
      src/Grid/Tools/PerPageSelector.php
  2. 27 4
      src/Widgets/Dropdown.php

+ 2 - 1
src/Grid/Tools/PerPageSelector.php

@@ -77,10 +77,11 @@ class PerPageSelector implements Renderable
         $options = $this->getOptions()->map(function ($option) {
             $url = app('request')->fullUrlWithQuery([$this->perPageName => $option]);
 
-            return "<a href=\"$url\">$option</a>";
+            return "<a href=\"{$url}\">$option</a>";
         })->toArray();
 
         $dropdown = Dropdown::make($options)
+            ->up()
             ->button($this->perPage)
             ->render();
 

+ 27 - 4
src/Widgets/Dropdown.php

@@ -45,6 +45,11 @@ class Dropdown extends Widget
      */
     protected $click = false;
 
+    /**
+     * @var string
+     */
+    protected $direction = 'down';
+
     public function __construct(array $options = [])
     {
         $this->options($options);
@@ -111,6 +116,23 @@ class Dropdown extends Widget
         return $this;
     }
 
+    public function direction(string $direction = 'down')
+    {
+        $this->direction = $direction;
+
+        return $this;
+    }
+
+    public function up()
+    {
+        return $this->direction('up');
+    }
+
+    public function down()
+    {
+        return $this->direction('down');
+    }
+
     /**
      * Show divider.
      *
@@ -222,10 +244,11 @@ class Dropdown extends Widget
     public function render()
     {
         $this->addVariables([
-            'options'  => $this->renderOptions(),
-            'button'   => $this->button,
-            'buttonId' => $this->buttonId,
-            'click'    => $this->click,
+            'options'   => $this->renderOptions(),
+            'button'    => $this->button,
+            'buttonId'  => $this->buttonId,
+            'click'     => $this->click,
+            'direction' => $this->direction,
         ]);
 
         return parent::render();