jqh 5 年之前
父節點
當前提交
0c29382efc
共有 3 個文件被更改,包括 28 次插入9 次删除
  1. 0 2
      src/Grid.php
  2. 27 6
      src/Grid/Concerns/HasExporter.php
  3. 1 1
      src/Grid/Concerns/HasFilter.php

+ 0 - 2
src/Grid.php

@@ -938,8 +938,6 @@ HTML;
      */
     public function render()
     {
-        $this->handleExportRequest();
-
         try {
             $this->callComposing();
 

+ 27 - 6
src/Grid/Concerns/HasExporter.php

@@ -12,13 +12,18 @@ trait HasExporter
     /**
      * @var Exporter
      */
-    protected $__exporter;
+    protected $exporter;
 
     /**
      * @var bool
      */
     protected $enableExporter = false;
 
+    /**
+     * @var bool
+     */
+    protected $exported = false;
+
     /**
      * Set exporter driver for Grid to export.
      *
@@ -53,12 +58,21 @@ trait HasExporter
      *
      * @return mixed
      */
-    protected function handleExportRequest($forceExport = false)
+    public function handleExportRequest($forceExport = false)
     {
-        if (! $scope = request($this->exporter()->queryName())) {
+        if (
+            $this->exported
+            || (
+                (! $this->allowExporter()
+                    || ! $scope = request($this->exporter()->queryName()))
+                && ! $forceExport
+            )
+        ) {
             return;
         }
 
+        $this->exported = true;
+
         $this->callBuilder();
 
         // clear output buffer.
@@ -67,6 +81,7 @@ trait HasExporter
         }
 
         if ($forceExport || $this->allowExporter()) {
+
             return $this->resolveExportDriver($scope)->export();
         }
     }
@@ -76,7 +91,13 @@ trait HasExporter
      */
     public function exporter()
     {
-        return $this->__exporter ?: ($this->__exporter = new Exporter($this));
+//        if (! $this->exporter) {
+//            $this->exporter = new Exporter($this);
+//
+//            $this->setExporterQueryName();
+//        }
+
+        return $this->exporter ?: ($this->exporter = new Exporter($this));
     }
 
     /**
@@ -86,11 +107,11 @@ trait HasExporter
      */
     protected function setExporterQueryName(string $name = null)
     {
-        if (! $this->allowExporter()) {
+        if (! $this->exporter) {
             return;
         }
 
-        $this->exporter()->setQueryName(($name ?: $this->getName()).'_export_');
+        $this->exporter->setQueryName(($name ?: $this->getName()).'_export_');
     }
 
     /**

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

@@ -40,8 +40,8 @@ trait HasFilter
     public function processFilter($toArray = true)
     {
         $this->callBuilder();
+        $this->handleExportRequest();
         $this->callFetchingCallbacks();
-
         $this->applyQuickSearch();
         $this->applyColumnFilter();
         $this->applySelectorQuery();