Browse Source

增加设置导出按钮相关配置参数方法

jqh 5 years ago
parent
commit
1f9082b0cb
3 changed files with 32 additions and 29 deletions
  1. 20 4
      src/Grid.php
  2. 6 23
      src/Grid/Concerns/Options.php
  3. 6 2
      src/Grid/Tools/ExportButton.php

+ 20 - 4
src/Grid.php

@@ -850,12 +850,28 @@ HTML
     }
 
     /**
-     * @param int|null $limit
-     * @return Grid
+     * @param array $options
+     * @return $this
      */
-    public function setExportLimit(?int $limit)
+    public function setExportOptions(array $options)
     {
-        return $this->option('export_limit', $limit);
+        if (isset($options['limit'])) {
+            $this->options['export_limit'] = $options['limit'];
+        }
+
+        if (isset($options['all'])) {
+            $this->options['show_export_all'] = $options['show_all'];
+        }
+
+        if (isset($options['current_page'])) {
+            $this->options['show_export_current_page'] = $options['current_page'];
+        }
+
+        if (isset($options['selected_rows'])) {
+            $this->options['show_export_selected_rows'] = $options['selected_rows'];
+        }
+
+        return $this;
     }
 
     /**

+ 6 - 23
src/Grid/Concerns/Options.php

@@ -12,8 +12,6 @@ trait Options
     protected $options = [
         'show_pagination'        => true,
         'show_filter'            => true,
-        'show_exporter'          => false,
-        'show_export_all'        => true,
         'show_actions'           => true,
         'show_quick_edit_button' => true,
         'show_edit_button'       => true,
@@ -31,7 +29,12 @@ trait Options
         'row_selector_label_name' => null,
         'row_selector_bg'         => 'var(--20)',
 
-        'export_limit'       => 50000,
+        'show_exporter'   => false,
+        'show_export_all' => true,
+        'show_export_current_page' => true,
+        'show_export_selected_rows' => true,
+        'export_limit'    => 50000,
+
         'dialog_form_area'   => ['700px', '670px'],
         'table_header_style' => 'table-header-gray',
 
@@ -357,26 +360,6 @@ trait Options
         return $this->disableExporter(!$val);
     }
 
-    /**
-     * Disable export all.
-     *
-     * @return $this
-     */
-    public function disableExporterAll(bool $disable = true)
-    {
-        return $this->option('show_export_all', !$disable);
-    }
-
-    /**
-     * Show export all option.
-     *
-     * @return $this
-     */
-    public function showExportAll(bool $val = true)
-    {
-        return $this->disableExporterAll(!$val);
-    }
-
     /**
      * Remove create button on grid.
      *

+ 6 - 2
src/Grid/Tools/ExportButton.php

@@ -51,7 +51,7 @@ JS;
      */
     protected function renderExportAll()
     {
-        if (!$this->grid->option('show_export_all')) {
+        if (! $this->grid->option('show_export_all')) {
             return;
         }
         $all = trans('admin.all');
@@ -64,6 +64,10 @@ JS;
      */
     protected function renderExportCurrentPage()
     {
+        if (! $this->grid->option('show_export_current_page')) {
+            return;
+        }
+
         $page = $this->grid->model()->getCurrentPage() ?: 1;
         $currentPage = trans('admin.current_page');
 
@@ -75,7 +79,7 @@ JS;
      */
     protected function renderExportSelectedRows()
     {
-        if (!$this->grid->option('show_row_selector')) {
+        if (! $this->grid->option('show_row_selector') || ! $this->grid->option('show_export_selected_rows')) {
             return;
         }