jqh 5 tahun lalu
induk
melakukan
12af55e457
3 mengubah file dengan 33 tambahan dan 33 penghapusan
  1. 0 18
      src/Grid.php
  2. 20 0
      src/Grid/Concerns/MultipleHeader.php
  3. 13 15
      src/Grid/Header.php

+ 0 - 18
src/Grid.php

@@ -642,24 +642,6 @@ HTML
         $this->sortHeaders();
     }
 
-    protected function createHeaderWithColumns(array $columns)
-    {
-        $headers = [];
-        /* @var Column $column */
-        foreach ($columns as $name => $column) {
-            $header = new Header($this, $column->getLabel(), [$name]);
-            $prio = $column->getDataPriority();
-            if (is_int($prio)) {
-                $header->responsive($prio);
-            }
-            if ($sorter = $column->sorter()) {
-                $header->setSorter($sorter);
-            }
-            $headers[] = $header;
-        }
-        return $headers;
-    }
-
     /**
      * @return Tools
      */

+ 20 - 0
src/Grid/Concerns/MultipleHeader.php

@@ -2,6 +2,7 @@
 
 namespace Dcat\Admin\Grid\Concerns;
 
+use Dcat\Admin\Grid\Column;
 use Dcat\Admin\Grid\Header;
 
 trait MultipleHeader
@@ -93,4 +94,23 @@ trait MultipleHeader
         );
     }
 
+    protected function createHeaderWithColumns(array $columns)
+    {
+        $headers = [];
+        /* @var Column $column */
+        foreach ($columns as $name => $column) {
+            $header = new Header($this, $column->getLabel(), [$name]);
+            $prio = $column->getDataPriority();
+            if (is_int($prio)) {
+                $header->responsive($prio);
+            }
+            if ($html = $column->renderHeader()) {
+                $header->append($html);
+            }
+            $headers[] = $header;
+        }
+        return $headers;
+    }
+
+
 }

+ 13 - 15
src/Grid/Header.php

@@ -3,11 +3,9 @@
 namespace Dcat\Admin\Grid;
 
 use Dcat\Admin\Widgets\Widget;
-use Illuminate\Contracts\Support\Renderable;
-use Dcat\Admin\Admin;
 use Dcat\Admin\Grid;
 
-class Header extends Widget implements Renderable
+class Header extends Widget
 {
     /**
      * @var Grid
@@ -25,9 +23,9 @@ class Header extends Widget implements Renderable
     protected $columnNames = [];
 
     /**
-     * @var string
+     * @var array
      */
-    protected $sorter;
+    protected $html = [];
 
     public function __construct(Grid $grid, string $label, array $columnNames)
     {
@@ -78,37 +76,37 @@ class Header extends Widget implements Renderable
      */
     public function responsive(int $priority = 1)
     {
-        $this->setAttribute('data-priority', $priority);
+        $this->setHtmlAttribute('data-priority', $priority);
 
         return $this;
     }
 
     /**
      *
-     * @param string $sorter
+     * @param string $html
      * @return $this
      */
-    public function setSorter(string $sorter)
+    public function append($html)
     {
-        $this->sorter = $sorter;
+        $this->html[] = $html;
+
         return $this;
     }
 
-    /**
-     * 初始化属性
-     */
     protected function setupAttributes()
     {
         $count = count($this->columnNames);
         if ($count == 1) {
-            $this->attributes['rowspan'] = 2;
+            $this->htmlAttributes['rowspan'] = 2;
         } else {
-            $this->attributes['colspan'] = $count;
+            $this->htmlAttributes['colspan'] = $count;
         }
     }
 
     public function render()
     {
-        return "<th {$this->formatAttributes()}>{$this->label}{$this->sorter}</th>";
+        $headers = implode(' ', $this->html);
+
+        return "<th {$this->formatHtmlAttributes()}>{$this->label}{$headers}</th>";
     }
 }