fix: wrong soft sort algorithm for numeric fields, closes #199

This commit is contained in:
Fabio Di Stasio 2022-03-05 21:58:56 +01:00
parent 4479a9600b
commit 763be8532d
1 changed files with 4 additions and 2 deletions

View File

@ -175,8 +175,10 @@ export default {
if (this.currentSort && !this.isHardSort) {
return [...this.localResults].sort((a, b) => {
let modifier = 1;
const valA = typeof a[this.currentSort] === 'string' ? a[this.currentSort].toLowerCase() : a[this.currentSort];
const valB = typeof b[this.currentSort] === 'string' ? b[this.currentSort].toLowerCase() : b[this.currentSort];
let valA = typeof a[this.currentSort] === 'string' ? a[this.currentSort].toLowerCase() : a[this.currentSort];
if (!isNaN(valA)) valA = Number(valA);
let valB = typeof b[this.currentSort] === 'string' ? b[this.currentSort].toLowerCase() : b[this.currentSort];
if (!isNaN(valB)) valB = Number(valB);
if (this.currentSortDir === 'desc') modifier = -1;
if (valA < valB) return -1 * modifier;
if (valA > valB) return 1 * modifier;