浏览代码

Fix bug - 4776 - Toggle All bug when checkbox / radio column is present (#4777)

* Fixes issue #4776
Added filter for selection control columns (radio & checkbox) to fix
toggle all bug when checkbox or radio column is present.

* Update bootstrap-table.js

Co-authored-by: 文翼 <wenzhixin2010@gmail.com>
Akshay Varma 6 年之前
父节点
当前提交
70a9a6cd4e
共有 1 个文件被更改,包括 8 次插入4 次删除
  1. 8 4
      src/bootstrap-table.js

+ 8 - 4
src/bootstrap-table.js

@@ -554,7 +554,7 @@ class BootstrapTable {
           ${this.constants.html.toolbarDropdown[0]}`)
           ${this.constants.html.toolbarDropdown[0]}`)
 
 
         if (opts.showColumnsToggleAll) {
         if (opts.showColumnsToggleAll) {
-          const allFieldsVisible = this.getVisibleColumns().length === this.columns.length
+          const allFieldsVisible = this.getVisibleColumns().length === this.columns.filter(column => !this.isSelectionColumn(column)).length
           html.push(
           html.push(
             Utils.sprintf(this.constants.html.toolbarDropdownItem,
             Utils.sprintf(this.constants.html.toolbarDropdownItem,
               Utils.sprintf('<input type="checkbox" class="toggle-all" %s> <span>%s</span>',
               Utils.sprintf('<input type="checkbox" class="toggle-all" %s> <span>%s</span>',
@@ -566,7 +566,7 @@ class BootstrapTable {
         }
         }
 
 
         this.columns.forEach((column, i) => {
         this.columns.forEach((column, i) => {
-          if (column.radio || column.checkbox) {
+          if (this.isSelectionColumn(column)) {
             return
             return
           }
           }
 
 
@@ -645,7 +645,7 @@ class BootstrapTable {
 
 
         this._toggleColumn($this.val(), $this.prop('checked'), false)
         this._toggleColumn($this.val(), $this.prop('checked'), false)
         this.trigger('column-switch', $this.data('field'), $this.prop('checked'))
         this.trigger('column-switch', $this.data('field'), $this.prop('checked'))
-        $toggleAll.prop('checked', $checkboxes.filter(':checked').length === this.columns.length)
+        $toggleAll.prop('checked', $checkboxes.filter(':checked').length === this.columns.filter(column => !this.isSelectionColumn(column)).length)
       })
       })
 
 
       $toggleAll.off('click').on('click', ({currentTarget}) => {
       $toggleAll.off('click').on('click', ({currentTarget}) => {
@@ -2363,13 +2363,17 @@ class BootstrapTable {
   }
   }
 
 
   getVisibleColumns () {
   getVisibleColumns () {
-    return this.columns.filter(({visible}) => visible)
+    return this.columns.filter((column) => column.visible && !this.isSelectionColumn(column))
   }
   }
 
 
   getHiddenColumns () {
   getHiddenColumns () {
     return this.columns.filter(({visible}) => !visible)
     return this.columns.filter(({visible}) => !visible)
   }
   }
 
 
+  isSelectionColumn (column) {
+    return column.radio || column.checkbox
+  }
+
   showAllColumns () {
   showAllColumns () {
     this._toggleAllColumns(true)
     this._toggleAllColumns(true)
   }
   }