Browse Source

Fixed sort reset bug

zhixin 5 years ago
parent
commit
05a7bdb970
2 changed files with 18 additions and 7 deletions
  1. 15 7
      src/bootstrap-table.js
  2. 3 0
      src/vue/BootstrapTable.vue

+ 15 - 7
src/bootstrap-table.js

@@ -402,11 +402,15 @@ class BootstrapTable {
     } else if (type === 'prepend') {
       this.options.data = [].concat(data).concat(this.options.data)
     } else {
-      this.options.data = data || this.options.data
+      data = data || this.options.data
+      this.options.data = Array.isArray(data) ? data : data[this.options.dataField]
     }
 
-    this.data = this.options.data
-    this.unsortedData = [...this.data]
+    this.data = [...this.options.data]
+
+    if (this.options.sortReset) {
+      this.unsortedData = [...this.data]
+    }
 
     if (this.options.sidePagination === 'server') {
       return
@@ -464,8 +468,8 @@ class BootstrapTable {
           this.$el.find(`tr td:nth-child(${index + 1})`).addClass(this.options.sortClass)
         }, 250)
       }
-    } else {
-      this.data = this.unsortedData
+    } else if (this.options.sortReset) {
+      this.data = [...this.unsortedData]
     }
   }
 
@@ -872,7 +876,7 @@ class BootstrapTable {
           }
 
           return true
-        }) : this.options.data
+        }) : [...this.options.data]
       }
 
       const visibleFields = this.getVisibleFields()
@@ -954,7 +958,11 @@ class BootstrapTable {
         }
         return false
       }) : this.data
-      this.unsortedData = [...this.data]
+
+      if (this.options.sortReset) {
+        this.unsortedData = [...this.data]
+      }
+
       this.initSort()
     }
   }

+ 3 - 0
src/vue/BootstrapTable.vue

@@ -5,6 +5,9 @@
 <script>
 const $ = window.jQuery
 const deepCopy = arg => {
+  if (arg === undefined) {
+    return arg
+  }
   return $.extend(true, Array.isArray(arg) ? [] : {}, arg)
 }