From 6fe075467d994d823490d3ed27e0cc8afd5ad74b Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Thu, 1 Nov 2018 16:40:35 +0530 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Sort=20rows=20numerically?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Default sort method uses alphabetical sort --- index.html | 14 ++++++++++++++ src/rowmanager.js | 9 ++++++--- src/style.css | 1 - src/utils.js | 4 ++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index de3b983..870129f 100644 --- a/index.html +++ b/index.html @@ -76,6 +76,12 @@ ] data = [ + { + 'Files': 'All Folders', + 'Size': '2M', + 'Last Updated': '', + 'indent': -1 + }, { 'Files': 'Documents', 'Size': '2M', @@ -130,7 +136,15 @@ 'Last Updated': 'A few seconds ago', 'indent': 2 }, + { + 'Files': 'dist', + 'Size': '21k', + 'Last Updated': 'A few seconds ago', + 'indent': 2 + }, ] + + data.map(d => d.indent++) } function buildData() { diff --git a/src/rowmanager.js b/src/rowmanager.js index fe1178c..d912b9b 100644 --- a/src/rowmanager.js +++ b/src/rowmanager.js @@ -4,7 +4,8 @@ import { nextTick, ensureArray, linkProperties, - uniq + uniq, + numberSortAsc } from './utils'; export default class RowManager { @@ -192,7 +193,7 @@ export default class RowManager { const childrenToShow = this.datamanager.getImmediateChildren(rowIndex); const visibleRows = this.bodyRenderer.visibleRows; - const rowsToShow = uniq([...childrenToShow, ...visibleRows]).sort(); + const rowsToShow = uniq([...childrenToShow, ...visibleRows]).sort(numberSortAsc); this.showRows(rowsToShow); } @@ -203,7 +204,9 @@ export default class RowManager { const rowsToHide = this.datamanager.getChildren(rowIndex); const visibleRows = this.bodyRenderer.visibleRows; - const rowsToShow = visibleRows.filter(rowIndex => !rowsToHide.includes(rowIndex)); + const rowsToShow = visibleRows + .filter(rowIndex => !rowsToHide.includes(rowIndex)) + .sort(numberSortAsc); rowsToHide.forEach(rowIndex => { const row = this.datamanager.getRow(rowIndex); diff --git a/src/style.css b/src/style.css index 14adb08..49cd546 100644 --- a/src/style.css +++ b/src/style.css @@ -45,7 +45,6 @@ .dt-scrollable { height: 40vw; overflow: auto; - border-bottom: 1px solid var(--dt-border-color); &--highlight-all { background-color: var(--dt-selection-highlight-color); diff --git a/src/utils.js b/src/utils.js index 3888b2a..4f49af7 100644 --- a/src/utils.js +++ b/src/utils.js @@ -130,3 +130,7 @@ export function ensureArray(val) { export function uniq(arr) { return _uniq(arr); } + +export function numberSortAsc(a, b) { + return a - b; +};