Эх сурвалжийг харах

HUE-6742 [editor] Incorrect Sorting With TIMESTAMP Column Type

Enrico Berti 8 жил өмнө
parent
commit
0c424a5805

+ 48 - 13
desktop/core/src/desktop/static/desktop/js/jquery.huedatatable.js

@@ -72,23 +72,43 @@
       }
       }
 
 
       var sortType = 'alpha';
       var sortType = 'alpha';
-      if (obj.cssClass && obj.cssClass === 'sort-numeric'){
-        sortType = 'numeric';
+      if (obj.cssClass) {
+        if (obj.cssClass === 'sort-numeric') {
+          sortType = 'numeric';
+        }
+        if (obj.cssClass === 'sort-date') {
+          sortType = 'date';
+        }
       }
       }
 
 
       if (way === -1 || way === 0) {
       if (way === -1 || way === 0) {
         data.sort(function (a, b) {
         data.sort(function (a, b) {
-          if (sortType === 'numeric'){
-            if (a[idx] === 'NULL'){
+          if (sortType === 'date') {
+            if (a[idx] === 'NULL') {
+              return -1;
+            }
+            if (b[idx] === 'NULL') {
+              return 1;
+            }
+            if (moment(a[idx].replace(/\ /, ' ')).valueOf() > moment(b[idx].replace(/\ /, ' ')).valueOf()) {
+              return 1;
+            }
+            if (moment(a[idx].replace(/\&nbsp;/, ' ')).valueOf() < moment(b[idx].replace(/\&nbsp;/, ' ')).valueOf()) {
+              return -1;
+            }
+            return 0;
+          }
+          else if (sortType === 'numeric') {
+            if (a[idx] === 'NULL') {
               return -1;
               return -1;
             }
             }
-            if (b[idx] === 'NULL'){
+            if (b[idx] === 'NULL') {
               return 1;
               return 1;
             }
             }
-            if (a[idx]*1 > b[idx]*1) {
+            if (a[idx] * 1 > b[idx] * 1) {
               return 1;
               return 1;
             }
             }
-            if (a[idx]*1 < b[idx]*1) {
+            if (a[idx] * 1 < b[idx] * 1) {
               return -1;
               return -1;
             }
             }
             return 0;
             return 0;
@@ -106,17 +126,32 @@
       }
       }
       else {
       else {
         data.sort(function (a, b) {
         data.sort(function (a, b) {
-          if (sortType === 'numeric'){
-            if (a[idx] === 'NULL'){
+          if (sortType === 'date') {
+            if (a[idx] === 'NULL') {
+              return 1;
+            }
+            if (b[idx] === 'NULL') {
+              return -1;
+            }
+            if (moment(a[idx].replace(/\&nbsp;/, ' ')).valueOf() > moment(b[idx].replace(/\&nbsp;/, ' ')).valueOf()) {
+              return -1;
+            }
+            if (moment(a[idx].replace(/\&nbsp;/, ' ')).valueOf() < moment(b[idx].replace(/\&nbsp;/, ' ')).valueOf()) {
+              return 1;
+            }
+            return 0;
+          }
+          else if (sortType === 'numeric') {
+            if (a[idx] === 'NULL') {
               return 1;
               return 1;
             }
             }
-            if (b[idx] === 'NULL'){
+            if (b[idx] === 'NULL') {
               return -1;
               return -1;
             }
             }
-            if (a[idx]*1 > b[idx]*1) {
+            if (a[idx] * 1 > b[idx] * 1) {
               return -1;
               return -1;
             }
             }
-            if (a[idx]*1 < b[idx]*1) {
+            if (a[idx] * 1 < b[idx] * 1) {
               return 1;
               return 1;
             }
             }
             return 0;
             return 0;
@@ -565,4 +600,4 @@
       self.$table.addClass('table-huedatatable');
       self.$table.addClass('table-huedatatable');
     });
     });
   };
   };
-})(jQuery, window, document);
+})(jQuery, window, document);

+ 1 - 1
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -1482,7 +1482,7 @@ var EditorViewModel = (function() {
       }
       }
 
 
       self.result.meta().forEach(function (meta) {
       self.result.meta().forEach(function (meta) {
-        if ($.inArray(meta.type, ['TINYINT_TYPE', 'SMALLINT_TYPE', 'INT_TYPE', 'BIGINT_TYPE', 'FLOAT_TYPE', 'DOUBLE_TYPE', 'DECIMAL_TYPE', 'TIMESTAMP_TYPE', 'DATE_TYPE']) > -1) {
+        if ($.inArray(meta.type, ['TINYINT_TYPE', 'SMALLINT_TYPE', 'INT_TYPE', 'BIGINT_TYPE', 'FLOAT_TYPE', 'DOUBLE_TYPE', 'DECIMAL_TYPE']) > -1) {
           meta.cssClass = 'sort-numeric';
           meta.cssClass = 'sort-numeric';
         } else if ($.inArray(meta.type, ['TIMESTAMP_TYPE', 'DATE_TYPE']) > -1) {
         } else if ($.inArray(meta.type, ['TIMESTAMP_TYPE', 'DATE_TYPE']) > -1) {
           meta.cssClass = 'sort-date';
           meta.cssClass = 'sort-date';