浏览代码

disable columns toggle checkboxes if the minimum count is reached (#4852)

Co-authored-by: Dennis Hernández <dennishernandezvargas@gmail.com>
Dustin Utecht 5 年之前
父节点
当前提交
4c79063c59
共有 1 个文件被更改,包括 10 次插入3 次删除
  1. 10 3
      src/bootstrap-table.js

+ 10 - 3
src/bootstrap-table.js

@@ -569,6 +569,13 @@ class BootstrapTable {
           html.push(this.constants.html.toolbarDropdownSeparator)
           html.push(this.constants.html.toolbarDropdownSeparator)
         }
         }
 
 
+        let visibleColumns = 0
+        this.columns.forEach((column, i) => {
+          if (column.visible) {
+            visibleColumns++
+          }
+        })
+
         this.columns.forEach((column, i) => {
         this.columns.forEach((column, i) => {
           if (this.isSelectionColumn(column)) {
           if (this.isSelectionColumn(column)) {
             return
             return
@@ -579,11 +586,11 @@ class BootstrapTable {
           }
           }
 
 
           const checked = column.visible ? ' checked="checked"' : ''
           const checked = column.visible ? ' checked="checked"' : ''
-
+          const disabled = (visibleColumns <= this.options.minimumCountColumns) && checked ? ' disabled="disabled"' : ''
           if (column.switchable) {
           if (column.switchable) {
             html.push(Utils.sprintf(this.constants.html.toolbarDropdownItem,
             html.push(Utils.sprintf(this.constants.html.toolbarDropdownItem,
-              Utils.sprintf('<input type="checkbox" data-field="%s" value="%s"%s> <span>%s</span>',
-                column.field, i, checked, column.title)))
+              Utils.sprintf('<input type="checkbox" data-field="%s" value="%s"%s%s> <span>%s</span>',
+                column.field, i, checked, disabled, column.title)))
             switchableCount++
             switchableCount++
           }
           }
         })
         })