Jiang qinghua 6 years ago
parent
commit
c5a4bf10dd
2 changed files with 24 additions and 13 deletions
  1. 3 7
      resources/views/grid/table.blade.php
  2. 21 6
      src/Grid.php

+ 3 - 7
resources/views/grid/table.blade.php

@@ -1,7 +1,3 @@
-@php
-    $__id = 'grid-'.\Illuminate\Support\Str::random(8);
-@endphp
-
 @if ($grid->option('show_toolbar')
     && ($grid->getTools()->has() || $grid->allowExportBtn() || $grid->allowCreateBtn() || $grid->allowQuickCreateBtn() || $grid->allowResponsive() || !empty($title)))
     <div class="box-header " >
@@ -12,11 +8,11 @@
                     <small>{!! $description!!}</small>
                 @endif
             </h4>
-            <div class="pull-right" data-responsive-table-toolbar="{{$__id}}">
+            <div class="pull-right" data-responsive-table-toolbar="{{$tableId}}">
                 {!! $grid->renderTools() !!} {!! $grid->renderCreateButton() !!} {!! $grid->renderExportButton() !!}
             </div>
         @else
-            <div class="pull-right" data-responsive-table-toolbar="{{$__id}}">
+            <div class="pull-right" data-responsive-table-toolbar="{{$tableId}}">
                 {!! $grid->renderCreateButton() !!} {!! $grid->renderExportButton() !!}
             </div>
 
@@ -31,7 +27,7 @@
 {!! $grid->renderHeader() !!}
 
 <div class="card-body panel-collapse collapse in table-responsive" {!! $grid->option('show_bordered') ? 'style="padding:3px 10px 10px"' : '' !!}>
-    <table class=" table table-hover responsive {{ $grid->option('show_bordered') ? 'table-bordered' : $grid->option('table_header_style') }} " id="{{$__id}}">
+    <table class=" table table-hover responsive {{ $grid->option('show_bordered') ? 'table-bordered' : $grid->option('table_header_style') }} " id="{{$tableId}}">
         <thead>
         @if ($headers = $grid->getMutipleHeaders())
             <tr>

+ 21 - 6
src/Grid.php

@@ -35,8 +35,8 @@ class Grid
         Concerns\MultipleHeader,
         Concerns\QuickSearch,
         Macroable {
-            __call as macroCall;
-        }
+        __call as macroCall;
+    }
 
     /**
      * The grid data model instance.
@@ -182,6 +182,11 @@ class Grid
      */
     protected $addNumberColumn = false;
 
+    /**
+     * @var string
+     */
+    protected $tableId;
+
     /**
      * Create a new grid instance.
      *
@@ -193,10 +198,11 @@ class Grid
         if ($repository) {
             $this->keyName = $repository->getKeyName();
         }
-        $this->model   = new Model($repository);
-        $this->columns = new Collection();
-        $this->rows    = new Collection();
-        $this->builder = $builder;
+        $this->model    = new Model($repository);
+        $this->columns  = new Collection();
+        $this->rows     = new Collection();
+        $this->builder  = $builder;
+        $this->tableId  = 'grid-'.Str::random(8);
 
         $this->model()->setGrid($this);
 
@@ -232,6 +238,14 @@ class Grid
         return $this->responsive;
     }
 
+    /**
+     * @return string
+     */
+    public function getTableId()
+    {
+        return $this->tableId;
+    }
+
     /**
      * @return bool
      */
@@ -1080,6 +1094,7 @@ HTML;
     protected function variables()
     {
         $this->variables['grid'] = $this;
+        $this->variables['tableId'] = $this->tableId;
 
         return $this->variables;
     }