Browse Source

refs #1678: Fixed sortStable option cannot work bug

zhixin 7 years ago
parent
commit
99ab515935
1 changed files with 4 additions and 3 deletions
  1. 4 3
      src/bootstrap-table.js

+ 4 - 3
src/bootstrap-table.js

@@ -964,7 +964,9 @@
       if (index !== -1) {
       if (index !== -1) {
         if (this.options.sortStable) {
         if (this.options.sortStable) {
           this.data.forEach((row, i) => {
           this.data.forEach((row, i) => {
-            row._position = i
+            if (!row.hasOwnProperty('_position')) {
+              row._position = i
+            }
           })
           })
         }
         }
 
 
@@ -978,7 +980,7 @@
 
 
           if (value !== undefined) {
           if (value !== undefined) {
             if (this.options.sortStable && value === 0) {
             if (this.options.sortStable && value === 0) {
-              return a._position - b._position
+              return order * (a._position - b._position)
             }
             }
             return order * value
             return order * value
           }
           }
@@ -994,7 +996,6 @@
           if (this.options.sortStable && aa === bb) {
           if (this.options.sortStable && aa === bb) {
             aa = a._position
             aa = a._position
             bb = b._position
             bb = b._position
-            return a._position - b._position
           }
           }
 
 
           // IF both values are numeric, do a numeric comparison
           // IF both values are numeric, do a numeric comparison