Skip to content

Commit

Permalink
fix #281
Browse files Browse the repository at this point in the history
  • Loading branch information
AllenFang committed Mar 29, 2016
1 parent 027c0ec commit f2e629c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/store/TableDataStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,27 @@ import Const from '../Const';

function _sort(arr, sortField, order, sortFunc, sortFuncExtraData) {
order = order.toLowerCase();
const isDesc = order === Const.SORT_DESC;
arr.sort((a, b) => {
if (sortFunc) {
return sortFunc(a, b, order, sortField, sortFuncExtraData);
} else {
if (order === Const.SORT_DESC) {
return a[sortField] > b[sortField] ? -1 : ((a[sortField] < b[sortField]) ? 1 : 0);
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]);
} else {
return a[sortField] > b[sortField] ? -1 : ((a[sortField] < b[sortField]) ? 1 : 0);
}
} else {
return a[sortField] < b[sortField] ? -1 : ((a[sortField] > b[sortField]) ? 1 : 0);
if (b[sortField] === null) return true;
if (a[sortField] === null) return false;
if (typeof a[sortField] === 'string') {
return a[sortField].localeCompare(b[sortField]);
} else {
return a[sortField] < b[sortField] ? -1 : ((a[sortField] > b[sortField]) ? 1 : 0);
}
}
}
});
Expand Down

0 comments on commit f2e629c

Please sign in to comment.