Browse Source

树状表格无数据返回空数据,不再返回404状态码 #843

jqh 4 years ago
parent
commit
a59a792c1d
2 changed files with 24 additions and 1 deletions
  1. 23 0
      src/Grid.php
  2. 1 1
      src/Grid/Concerns/HasTree.php

+ 23 - 0
src/Grid.php

@@ -176,6 +176,11 @@ class Grid
      */
     protected $request;
 
+    /**
+     * @var bool
+     */
+    protected $show = true;
+
     /**
      * Create a new grid instance.
      *
@@ -878,6 +883,20 @@ HTML;
         return $this;
     }
 
+    /**
+     * 设置是否显示.
+     *
+     * @param bool $value
+     *
+     * @return $this
+     */
+    public function show(bool $value = true)
+    {
+        $this->show = $value;
+
+        return $this;
+    }
+
     /**
      * Get the string contents of the grid view.
      *
@@ -901,6 +920,10 @@ HTML;
      */
     protected function doWrap()
     {
+        if (! $this->show) {
+            return;
+        }
+
         $view = view($this->view, $this->variables());
 
         if (! $wrapper = $this->wrapper) {

+ 1 - 1
src/Grid/Concerns/HasTree.php

@@ -66,7 +66,7 @@ trait HasTree
             }
 
             if ($collection->isEmpty()) {
-                abort(404);
+                return $grid->show(false);
             }
 
             $this->buildChildrenNodesPagination();