浏览代码

Fixed toggle column bug with complex header

zhixin 3 年之前
父节点
当前提交
c6707626c4
共有 2 个文件被更改,包括 16 次插入2 次删除
  1. 1 1
      src/bootstrap-table.js
  2. 15 1
      src/utils/index.js

+ 1 - 1
src/bootstrap-table.js

@@ -263,7 +263,7 @@ class BootstrapTable {
       searchables: []
       searchables: []
     }
     }
 
 
-    Utils.updateFieldGroup(this.options.columns)
+    Utils.updateFieldGroup(this.options.columns, this.columns)
 
 
     this.options.columns.forEach((columns, i) => {
     this.options.columns.forEach((columns, i) => {
       const html = []
       const html = []

+ 15 - 1
src/utils/index.js

@@ -207,7 +207,7 @@ export default {
     return value.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
     return value.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
   },
   },
 
 
-  updateFieldGroup (columns) {
+  updateFieldGroup (columns, fieldColumns) {
     const allColumns = [].concat(...columns)
     const allColumns = [].concat(...columns)
 
 
     for (const c of columns) {
     for (const c of columns) {
@@ -227,6 +227,20 @@ export default {
         }
         }
       }
       }
     }
     }
+
+    if (columns.length < 2) {
+      return
+    }
+
+    for (const column of fieldColumns) {
+      const sameColumns = allColumns.filter(col => col.fieldIndex === column.fieldIndex)
+
+      if (sameColumns.length > 1) {
+        for (const c of sameColumns) {
+          c.visible = column.visible
+        }
+      }
+    }
   },
   },
 
 
   getScrollBarWidth () {
   getScrollBarWidth () {