From a56edb9ff43708bb13ea11bcd1752e1239e8b80f Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 10 Mar 2016 13:31:40 -0800 Subject: [PATCH] [table] #707 Fixed sorting on insert for numbers Added metadata to event generator --- example/eventGenerator/bundle.js | 2 ++ .../table/src/controllers/MCTTableController.js | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/example/eventGenerator/bundle.js b/example/eventGenerator/bundle.js index 6773442494..9a3a435c0f 100644 --- a/example/eventGenerator/bundle.js +++ b/example/eventGenerator/bundle.js @@ -66,6 +66,8 @@ define([ ], "ranges": [ { + "key": "message", + "name": "Message", "format": "string" } ] diff --git a/platform/features/table/src/controllers/MCTTableController.js b/platform/features/table/src/controllers/MCTTableController.js index 80270bce06..4bae5915d1 100644 --- a/platform/features/table/src/controllers/MCTTableController.js +++ b/platform/features/table/src/controllers/MCTTableController.js @@ -262,13 +262,17 @@ define( sortKey = this.$scope.sortColumn; function binarySearch(searchArray, searchElement, min, max){ - var sampleAt = Math.floor((max - min) / 2) + min; - + var sampleAt = Math.floor((max - min) / 2) + min, + valA, + valB; if (max < min) { return min; // Element is not in array, min gives direction } - switch(self.sortComparator(searchElement[sortKey].text, searchArray[sampleAt][sortKey].text)) { + valA = isNaN(searchElement[sortKey].text) ? searchElement[sortKey].text : parseFloat(searchElement[sortKey].text); + valB = isNaN(searchArray[sampleAt][sortKey].text) ? searchArray[sampleAt][sortKey].text : searchArray[sampleAt][sortKey].text; + + switch(self.sortComparator(valA, valB)) { case -1: return binarySearch(searchArray, searchElement, min, sampleAt - 1); case 0 :