浏览代码

fix #4182: Disabled export button when exportDataType is 'selected' and selection empty.

zhixin 6 年之前
父节点
当前提交
9cd1129e23
共有 1 个文件被更改,包括 19 次插入4 次删除
  1. 19 4
      src/extensions/export/bootstrap-table-export.js

+ 19 - 4
src/extensions/export/bootstrap-table-export.js

@@ -74,12 +74,13 @@
         return
       }
       const $btnGroup = this.$toolbar.find('>.btn-group')
-      let $export = $btnGroup.find('div.export')
+      this.$export = $btnGroup.find('div.export')
 
-      if ($export.length) {
+      if (this.$export.length) {
+        this.updateExportButton()
         return
       }
-      $export = $(`
+      this.$export = $(`
         <div class="export btn-group">
         <button class="btn btn-${o.buttonsClass} btn-${o.iconSize} dropdown-toggle"
           aria-label="export type"
@@ -93,7 +94,9 @@
         </div>
       `).appendTo($btnGroup)
 
-      const $menu = $export.find('.dropdown-menu')
+      this.updateExportButton()
+
+      const $menu = this.$export.find('.dropdown-menu')
       let exportTypes = o.exportTypes
 
       if (typeof exportTypes === 'string') {
@@ -206,5 +209,17 @@
         doExport()
       }
     }
+
+    updateSelected () {
+      super.updateSelected()
+      this.updateExportButton()
+    }
+
+    updateExportButton () {
+      if (this.options.exportDataType === 'selected') {
+        this.$export.find('> button')
+          .prop('disabled', !this.getSelections().length)
+      }
+    }
   }
 })(jQuery)