From 1a0eba65a0ddb59f5d5fc754d47cad2a9be0a42f Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 24 Jun 2019 15:08:39 +0530 Subject: [PATCH 1/3] fix: Number compare - 006 will match abc006 - 1230 will match 1,230 (formatted), 1230 and abc1230 --- src/filterRows.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/filterRows.js b/src/filterRows.js index f4849ce..9e9fd78 100644 --- a/src/filterRows.js +++ b/src/filterRows.js @@ -111,12 +111,12 @@ function getFilterMethod(filter) { containsNumber(keyword, cells) { return cells .filter(cell => { - let hay = numberCompareValue(cell); - if (isNaN(hay)) { - hay = stringCompareValue(cell); - } - const needle = keyword; - return !needle || hay.toString().includes(needle); + let number = parseFloat(keyword, 10); + let string = keyword; + let hayNumber = numberCompareValue(cell); + let hayString = stringCompareValue(cell); + + return number === hayNumber || hayString.includes(string); }) .map(cell => cell.rowIndex); } @@ -166,7 +166,7 @@ function guessFilter(keyword = '') { if (isNumber(compareString)) { return { type: 'containsNumber', - text: parseFloat(keyword, 10) + text: compareString }; } From b1962dffcf6161c3b81b690f58b69be9c2f23c59 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 24 Jun 2019 15:11:24 +0530 Subject: [PATCH 2/3] fix: Submit cell if editing deactivated Editing cell will now submit the value when the editing is deactivated, except when Escape key is pressed. It will also submit when Tab key is pressed. --- src/cellmanager.js | 67 +++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 27 deletions(-) diff --git a/src/cellmanager.js b/src/cellmanager.js index 37ee7b1..739c16c 100644 --- a/src/cellmanager.js +++ b/src/cellmanager.js @@ -51,34 +51,19 @@ export default class CellManager { this.activateEditing(this.$focusedCell); } else if (this.$editingCell) { // enter keypress on editing cell - this.submitEditing(); this.deactivateEditing(); } }); + this.keyboard.on('tab, shift+tab', (e) => { + if (this.$editingCell) { + // tab keypress on editing cell + this.deactivateEditing(); + this.focusCellInDirection(e.shiftKey ? 'left' : 'right'); + } + }); } bindKeyboardNav() { - const focusCell = (direction) => { - if (!this.$focusedCell || this.$editingCell) { - return false; - } - - let $cell = this.$focusedCell; - - if (direction === 'left' || direction === 'shift+tab') { - $cell = this.getLeftCell$($cell); - } else if (direction === 'right' || direction === 'tab') { - $cell = this.getRightCell$($cell); - } else if (direction === 'up') { - $cell = this.getAboveCell$($cell); - } else if (direction === 'down') { - $cell = this.getBelowCell$($cell); - } - - this.focusCell($cell); - return true; - }; - const focusLastCell = (direction) => { if (!this.$focusedCell || this.$editingCell) { return false; @@ -105,13 +90,13 @@ export default class CellManager { }; ['left', 'right', 'up', 'down', 'tab', 'shift+tab'] - .map(direction => this.keyboard.on(direction, () => focusCell(direction))); + .map(direction => this.keyboard.on(direction, () => this.focusCellInDirection(direction))); ['left', 'right', 'up', 'down'] .map(direction => this.keyboard.on(`ctrl+${direction}`, () => focusLastCell(direction))); this.keyboard.on('esc', () => { - this.deactivateEditing(); + this.deactivateEditing(false); this.columnmanager.toggleFilter(false); }); @@ -463,7 +448,10 @@ export default class CellManager { } } - deactivateEditing() { + deactivateEditing(submitValue = true) { + if (submitValue) { + this.submitEditing(); + } // keep focus on the cell so that keyboard navigation works if (this.$focusedCell) this.$focusedCell.focus(); @@ -514,7 +502,9 @@ export default class CellManager { } submitEditing() { - if (!this.$editingCell) return; + let promise = Promise.resolve(); + if (!this.$editingCell) return promise; + const $cell = this.$editingCell; const { rowIndex, @@ -533,7 +523,7 @@ export default class CellManager { valuePromise = Promise.resolve(valuePromise); } - valuePromise.then((value) => { + promise = valuePromise.then((value) => { const done = editor.setValue(value, rowIndex, col); const oldValue = this.getCell(colIndex, rowIndex).content; @@ -548,11 +538,13 @@ export default class CellManager { this.updateCell(colIndex, rowIndex, oldValue); }); } + return done; }); } } this.currentCellEditor = null; + return promise; } copyCellContents($cell1, $cell2) { @@ -654,6 +646,27 @@ export default class CellManager { return colIndex < this.columnmanager.getFirstColumnIndex(); } + focusCellInDirection(direction) { + if (!this.$focusedCell || this.$editingCell) { + return false; + } + + let $cell = this.$focusedCell; + + if (direction === 'left' || direction === 'shift+tab') { + $cell = this.getLeftCell$($cell); + } else if (direction === 'right' || direction === 'tab') { + $cell = this.getRightCell$($cell); + } else if (direction === 'up') { + $cell = this.getAboveCell$($cell); + } else if (direction === 'down') { + $cell = this.getBelowCell$($cell); + } + + this.focusCell($cell); + return true; + } + getCell$(colIndex, rowIndex) { return $(this.selector(colIndex, rowIndex), this.bodyScrollable); } From 40c8e51e86bd55933b93b41afb379abe78537ad7 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Mon, 24 Jun 2019 15:19:09 +0530 Subject: [PATCH 3/3] fix: Set dropdown background as header background --- src/style.css | 1 + 1 file changed, 1 insertion(+) diff --git a/src/style.css b/src/style.css index ef1555d..a4f2b57 100644 --- a/src/style.css +++ b/src/style.css @@ -188,6 +188,7 @@ &__toggle { opacity: 0; + background-color: var(--dt-header-cell-bg); } &__list {