Browse Source

Merge pull request #5381 from Moutard3/patch-1

Fix reorder column when a column is removed/added
文翼 5 years ago
parent
commit
9fa4c82299
1 changed files with 8 additions and 1 deletions
  1. 8 1
      src/extensions/reorder-columns/bootstrap-table-reorder-columns.js

+ 8 - 1
src/extensions/reorder-columns/bootstrap-table-reorder-columns.js

@@ -6,11 +6,18 @@
  */
 
 $.akottr.dragtable.prototype._restoreState = function (persistObj) {
+  let i = 0
+
   for (const [field, value] of Object.entries(persistObj)) {
     const $th = this.originalTable.el.find(`th[data-field="${field}"]`)
 
+    if (!$th.length) {
+      i++
+      continue
+    }
+
     this.originalTable.startIndex = $th.prevAll().length + 1
-    this.originalTable.endIndex = parseInt(value, 10) + 1
+    this.originalTable.endIndex = parseInt(value, 10) + 1 - i
     this._bubbleCols()
   }
 }