Skip to content

Commit

Permalink
Fix sorting for null values
Browse files Browse the repository at this point in the history
Columns with some null values are not sorted correctly.
  • Loading branch information
Kurtas committed May 10, 2016
1 parent b572cdb commit 6a1c88b
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/store/TableDataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ function _sort(arr, sortField, order, sortFunc, sortFuncExtraData) {
if (sortFunc) {
return sortFunc(a, b, order, sortField, sortFuncExtraData);
} else {
const valueA = a[sortField] === null ? '' : a[sortField];
const valueB = b[sortField] === null ? '' : b[sortField];
if (isDesc) {
if (b[sortField] === null) return false;
if (a[sortField] === null) return true;
if (typeof b[sortField] === 'string') {
return b[sortField].localeCompare(a[sortField]);
if (typeof valueB === 'string') {
return valueB.localeCompare(valueA);
} else {
return a[sortField] > b[sortField] ? -1 : ((a[sortField] < b[sortField]) ? 1 : 0);
return valueA > valueB ? -1 : ((valueA < valueB) ? 1 : 0);
}
} else {
if (b[sortField] === null) return true;
if (a[sortField] === null) return false;
if (typeof a[sortField] === 'string') {
return a[sortField].localeCompare(b[sortField]);
if (typeof valueA === 'string') {
return valueA.localeCompare(valueB);
} else {
return a[sortField] < b[sortField] ? -1 : ((a[sortField] > b[sortField]) ? 1 : 0);
return valueA < valueB ? -1 : ((valueA > valueB) ? 1 : 0);
}
}
}
Expand Down

0 comments on commit 6a1c88b

Please sign in to comment.