Ver Fonte

修复同个页面构建多个grid时filter冲突问题

jqh há 6 anos atrás
pai
commit
4dce308ab0
2 ficheiros alterados com 12 adições e 1 exclusões
  1. 10 0
      src/Grid/Filter.php
  2. 2 1
      src/Grid/Tools/FilterButton.php

+ 10 - 0
src/Grid/Filter.php

@@ -198,6 +198,8 @@ class Filter implements Renderable
 
         $this->primaryKey = $model->getKeyName();
 
+        $this->filterID = $this->generateFilterId();
+
         $this->initLayout();
 
         $this->scopes = new Collection();
@@ -213,6 +215,14 @@ class Filter implements Renderable
         $this->layout = new Filter\Layout\Layout($this);
     }
 
+    /**
+     * @return string
+     */
+    protected function generateFilterId()
+    {
+        return 'filter-box-'.Str::random(8);
+    }
+
     /**
      * Set action of search form.
      *

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

@@ -3,6 +3,7 @@
 namespace Dcat\Admin\Grid\Tools;
 
 use Dcat\Admin\Admin;
+use Illuminate\Support\Str;
 
 class FilterButton extends AbstractTool
 {
@@ -32,7 +33,7 @@ class FilterButton extends AbstractTool
     protected function getElementClassName()
     {
         if (!$this->btnClassName) {
-            $this->btnClassName = uniqid().'-filter-btn';
+            $this->btnClassName = 'filter-btn-'.Str::random(8);
         }
 
         return $this->btnClassName;