Browse Source

Fixed sorting bug when one value is numeric and the other is not.

Marco Braga 11 years ago
parent
commit
4c9e2dd7bd
1 changed files with 13 additions and 6 deletions
  1. 13 6
      src/bootstrap-table.js

+ 13 - 6
src/bootstrap-table.js

@@ -502,12 +502,8 @@
                     return order * value;
                 }
 
-                // Convert numerical values form string to float.
-                if ($.isNumeric(aa)) {
-                    aa = parseFloat(aa);
-                }
-                if ($.isNumeric(bb)) {
-                    bb = parseFloat(bb);
+                if (value !== undefined) {
+                    return order * value;
                 }
 
                 // Fix #161: undefined or null string sort bug.
@@ -518,7 +514,11 @@
                     bb = '';
                 }
                 
+				// IF both values are numeric, do a numeric comparison
                 if ($.isNumeric(aa) && $.isNumeric(bb)) {
+                    // Convert numerical values form string to float.
+                    aa = parseFloat(aa);
+                    bb = parseFloat(bb);
                     if (aa < bb) {
                         return order * -1;
                     }
@@ -528,6 +528,13 @@
                 if (aa === bb) {
                     return 0;
                 }
+
+				// If value is not a string, convert to string
+                if (typeof aa !== 'string')
+                {
+                    aa = aa.toString();
+                }
+
                 if (aa.localeCompare(bb) === -1) {
                     return order * -1;
                 }