fix: 🐛 Sort rows numerically

Default sort method uses alphabetical sort
This commit is contained in:
Faris Ansari 2018-11-01 16:40:35 +05:30
parent cfbb891737
commit 6fe075467d
4 changed files with 24 additions and 4 deletions

View File

@ -76,6 +76,12 @@
] ]
data = [ data = [
{
'Files': 'All Folders',
'Size': '2M',
'Last Updated': '',
'indent': -1
},
{ {
'Files': 'Documents', 'Files': 'Documents',
'Size': '2M', 'Size': '2M',
@ -130,7 +136,15 @@
'Last Updated': 'A few seconds ago', 'Last Updated': 'A few seconds ago',
'indent': 2 'indent': 2
}, },
{
'Files': 'dist',
'Size': '21k',
'Last Updated': 'A few seconds ago',
'indent': 2
},
] ]
data.map(d => d.indent++)
} }
function buildData() { function buildData() {

View File

@ -4,7 +4,8 @@ import {
nextTick, nextTick,
ensureArray, ensureArray,
linkProperties, linkProperties,
uniq uniq,
numberSortAsc
} from './utils'; } from './utils';
export default class RowManager { export default class RowManager {
@ -192,7 +193,7 @@ export default class RowManager {
const childrenToShow = this.datamanager.getImmediateChildren(rowIndex); const childrenToShow = this.datamanager.getImmediateChildren(rowIndex);
const visibleRows = this.bodyRenderer.visibleRows; const visibleRows = this.bodyRenderer.visibleRows;
const rowsToShow = uniq([...childrenToShow, ...visibleRows]).sort(); const rowsToShow = uniq([...childrenToShow, ...visibleRows]).sort(numberSortAsc);
this.showRows(rowsToShow); this.showRows(rowsToShow);
} }
@ -203,7 +204,9 @@ export default class RowManager {
const rowsToHide = this.datamanager.getChildren(rowIndex); const rowsToHide = this.datamanager.getChildren(rowIndex);
const visibleRows = this.bodyRenderer.visibleRows; 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 => { rowsToHide.forEach(rowIndex => {
const row = this.datamanager.getRow(rowIndex); const row = this.datamanager.getRow(rowIndex);

View File

@ -45,7 +45,6 @@
.dt-scrollable { .dt-scrollable {
height: 40vw; height: 40vw;
overflow: auto; overflow: auto;
border-bottom: 1px solid var(--dt-border-color);
&--highlight-all { &--highlight-all {
background-color: var(--dt-selection-highlight-color); background-color: var(--dt-selection-highlight-color);

View File

@ -130,3 +130,7 @@ export function ensureArray(val) {
export function uniq(arr) { export function uniq(arr) {
return _uniq(arr); return _uniq(arr);
} }
export function numberSortAsc(a, b) {
return a - b;
};