jqh 5 years ago
parent
commit
396c27deda
2 changed files with 14 additions and 5 deletions
  1. 10 4
      src/Grid/Filter/Presenter/Select.php
  2. 4 1
      src/Grid/Filter/Presenter/SelectResource.php

+ 10 - 4
src/Grid/Filter/Presenter/Select.php

@@ -10,6 +10,11 @@ use Illuminate\Support\Arr;
 
 class Select extends Presenter
 {
+    /**
+     * @var string
+     */
+    protected $elementClass = null;
+
     /**
      * Options of select.
      *
@@ -273,7 +278,8 @@ JS;
      */
     protected function getElementClass() : string
     {
-        return str_replace('.', '_', $this->filter->getColumn());
+        return $this->elementClass ?:
+            ($this->elementClass = $this->getClass($this->filter->getColumn()));
     }
 
     /**
@@ -288,11 +294,11 @@ JS;
      */
     public function load($target, $resourceUrl, $idField = 'id', $textField = 'text') : self
     {
-        $column = $this->filter->getColumn();
+        $class = $this->getElementClass();
 
         $script = <<<JS
-$(document).off('change', ".{$this->getClass($column)}");
-$(document).on('change', ".{$this->getClass($column)}", function () {
+$(document).off('change', ".{$class}");
+$(document).on('change', ".{$class}", function () {
     var target = $(this).closest('form').find(".{$this->getClass($target)}");
     $.get("$resourceUrl?q="+this.value, function (data) {
         target.find("option").remove();

+ 4 - 1
src/Grid/Filter/Presenter/SelectResource.php

@@ -172,7 +172,10 @@ class SelectResource extends Presenter
      */
     public function variables() : array
     {
-        $this->value = request($this->filter->getColumn(), $this->filter->getValue() ?: $this->filter->getDefault());
+        $this->value = request(
+            $this->filter->getColumn(),
+            $this->filter->getValue() ?: $this->filter->getDefault()
+        );
 
         $this->formatOptions();
         $this->formatValue();