ソースを参照

Fix #161: undefined or null string sort bug.

zhixin 11 年 前
コミット
a55330c757
1 ファイル変更13 行追加3 行削除
  1. 13 3
      src/bootstrap-table.js

+ 13 - 3
src/bootstrap-table.js

@@ -425,16 +425,26 @@
 
 
         if (index !== -1) {
         if (index !== -1) {
             this.data.sort(function (a, b) {
             this.data.sort(function (a, b) {
-                var value = calculateObjectValue(that.header, that.header.sorters[index], [a[name], b[name]]);
+                var aa = a[name],
+                    bb = b[name],
+                    value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
 
 
                 if (value !== undefined) {
                 if (value !== undefined) {
                     return order * value;
                     return order * value;
                 }
                 }
 
 
-                if (a[name] === b[name]) {
+                // Fix #161: undefined or null string sort bug.
+                if (aa === null) {
+                    aa = '';
+                }
+                if (bb === null) {
+                    bb = '';
+                }
+
+                if (aa === bb) {
                     return 0;
                     return 0;
                 }
                 }
-                if (a[name] < b[name]) {
+                if (aa < bb) {
                     return order * -1;
                     return order * -1;
                 }
                 }
                 return order;
                 return order;