zeppelin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prabhjyotsi...@apache.org
Subject zeppelin git commit: [ZEPPELIN-3450] Number sorting issue
Date Wed, 23 May 2018 05:45:36 GMT
Repository: zeppelin
Updated Branches:
  refs/heads/master fbe42d2d3 -> 3ca7d7237


[ZEPPELIN-3450] Number sorting issue

 ### What is this PR for?
 Sorting value with types [NUMBER,STRING,DATE].

 ### What type of PR is it?
 [Bug Fix]

 ### What is the Jira issue?
 * [ZEPPELIN-3450](https://issues.apache.org/jira/browse/ZEPPELIN-3450)

 ### How should this be tested?
 First select the type of sorting, then click the sort asc/desc.

* Does the licenses files need update?
* Is there breaking changes for older versions?
* Does this needs documentation?

Author: sameer79 <findsameershaikh@yahoo.co.in>

Closes #2963 from sameer79/ZEPPELIN-3450 and squashes the following commits:

b83bda925 [sameer79] [ZEPPELIN-3450] Number sorting issue

Change-Id: I3346102ca868ac6538b5491cc294aec0e1d80479


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/3ca7d723
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/3ca7d723
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/3ca7d723

Branch: refs/heads/master
Commit: 3ca7d723704bb58577830cd0c6390453e04d7f10
Parents: fbe42d2
Author: sameer79 <findsameershaikh@yahoo.co.in>
Authored: Wed May 9 11:02:04 2018 +0530
Committer: Prabhjyot Singh <prabhjyotsingh@gmail.com>
Committed: Wed May 23 11:15:31 2018 +0530

----------------------------------------------------------------------
 .../builtins/visualization-table.js             | 23 +++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/3ca7d723/zeppelin-web/src/app/visualization/builtins/visualization-table.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/app/visualization/builtins/visualization-table.js b/zeppelin-web/src/app/visualization/builtins/visualization-table.js
index ebb68fa..831bf95 100644
--- a/zeppelin-web/src/app/visualization/builtins/visualization-table.js
+++ b/zeppelin-web/src/app/visualization/builtins/visualization-table.js
@@ -82,6 +82,10 @@ export default class TableVisualization extends Visualization {
     return width;
   }
 
+  getSortedValue(a, b) {
+    return a > b ? 1 : a === b ? 0 : -1;
+  }
+
   createGridOptions(tableData, onRegisterApiCallback, config) {
     const rows = tableData.rows;
     const columnNames = tableData.columns.map((c) => c.name);
@@ -105,6 +109,7 @@ export default class TableVisualization extends Visualization {
       exporterExcelFilename: 'myFile.xlsx',
 
       columnDefs: columnNames.map((colName) => {
+        const self = this;
         return {
           displayName: colName,
           name: colName,
@@ -121,6 +126,18 @@ export default class TableVisualization extends Visualization {
           `,
           minWidth: this.getColumnMinWidth(colName),
           width: '*',
+          sortingAlgorithm: function(a, b, row1, row2, sortType, gridCol) {
+            const colType = gridCol.colDef.type.toLowerCase();
+            if (colType === TableColumnType.NUMBER) {
+              return self.getSortedValue(a, b);
+            } else if (colType === TableColumnType.STRING) {
+              return self.getSortedValue(a.toString(), b.toString());
+            } else if (colType === TableColumnType.DATE) {
+              return self.getSortedValue(new Date(a), new Date(b));
+            } else {
+              return self.getSortedValue(a, b);
+            }
+          },
         };
       }),
       rowEditWaitInterval: -1, /** disable saveRow event */
@@ -339,12 +356,12 @@ export default class TableVisualization extends Visualization {
       // create, compile and append grid elem
       gridElem = angular.element(
         `<div id="${gridElemId}" ui-grid="${gridElemId}"
-              ui-grid-edit ui-grid-row-edit 
-              ui-grid-pagination 
+              ui-grid-edit ui-grid-row-edit
+              ui-grid-pagination
               ui-grid-selection
               ui-grid-cellNav ui-grid-pinning
               ui-grid-empty-base-layer
-              ui-grid-resize-columns 
+              ui-grid-resize-columns
               ui-grid-move-columns
               ui-grid-grouping
               ui-grid-save-state


Mime
View raw message