Skip to content

Commit 6a1c88b

Browse files
committed
Fix sorting for null values
Columns with some null values are not sorted correctly.
1 parent b572cdb commit 6a1c88b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/store/TableDataStore.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@ function _sort(arr, sortField, order, sortFunc, sortFuncExtraData) {
1111
if (sortFunc) {
1212
return sortFunc(a, b, order, sortField, sortFuncExtraData);
1313
} else {
14+
const valueA = a[sortField] === null ? '' : a[sortField];
15+
const valueB = b[sortField] === null ? '' : b[sortField];
1416
if (isDesc) {
15-
if (b[sortField] === null) return false;
16-
if (a[sortField] === null) return true;
17-
if (typeof b[sortField] === 'string') {
18-
return b[sortField].localeCompare(a[sortField]);
17+
if (typeof valueB === 'string') {
18+
return valueB.localeCompare(valueA);
1919
} else {
20-
return a[sortField] > b[sortField] ? -1 : ((a[sortField] < b[sortField]) ? 1 : 0);
20+
return valueA > valueB ? -1 : ((valueA < valueB) ? 1 : 0);
2121
}
2222
} else {
23-
if (b[sortField] === null) return true;
24-
if (a[sortField] === null) return false;
25-
if (typeof a[sortField] === 'string') {
26-
return a[sortField].localeCompare(b[sortField]);
23+
if (typeof valueA === 'string') {
24+
return valueA.localeCompare(valueB);
2725
} else {
28-
return a[sortField] < b[sortField] ? -1 : ((a[sortField] > b[sortField]) ? 1 : 0);
26+
return valueA < valueB ? -1 : ((valueA > valueB) ? 1 : 0);
2927
}
3028
}
3129
}

0 commit comments

Comments
 (0)