From 01d93306f3c44e65f245072941ae1c0c1b6c7a28 Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Wed, 5 Jul 2017 11:32:05 -0700 Subject: [PATCH] Fix insertion point scan --- .../table/src/controllers/MCTTableController.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/platform/features/table/src/controllers/MCTTableController.js b/platform/features/table/src/controllers/MCTTableController.js index 52d1c2f7f4..4ad17304ff 100644 --- a/platform/features/table/src/controllers/MCTTableController.js +++ b/platform/features/table/src/controllers/MCTTableController.js @@ -437,15 +437,21 @@ define( */ MCTTableController.prototype.findInsertionPoint = function (searchArray, searchElement) { var index; - var textIndex; + var testIndex; var first = searchArray[0]; var last = searchArray[searchArray.length - 1]; + if (first) { + first = first[this.$scope.sortColumn].text; + } + if (last) { + last = last[this.$scope.sortColumn].text; + } // Shortcut check for append/prepend - if (first && this.sortComparator(first, searchElement) <= 0) { + if (first && this.sortComparator(first, searchElement) >= 0) { index = testIndex = 0; - } else if (last && this.sortComparator(last, searchElement) >= 0) { - index = testIndex = searchArray.length - 1; + } else if (last && this.sortComparator(last, searchElement) <= 0) { + index = testIndex = searchArray.length; } else { // use a binary search to find the correct insertion point index = testIndex = this.binarySearch(