Skip to content

Commit

Permalink
Merge pull request #942 from jbetancur/fix/937
Browse files Browse the repository at this point in the history
Fix/937
  • Loading branch information
jbetancur authored Oct 10, 2021
2 parents 6dfba87 + 40c1f77 commit f4e6325
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-data-table-component",
"version": "7.4.2",
"version": "7.4.3",
"description": "A simple to use declarative react based data table",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
Expand Down
56 changes: 27 additions & 29 deletions src/DataTable/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,40 @@ export function sort<T>(
return sortFn(rows.slice(0), selector as Selector<T>, direction);
}

return rows
.sort((a: T, b: T) => {
let aValue;
let bValue;

if (typeof selector === 'string') {
aValue = parseSelector(a, selector);
bValue = parseSelector(b, selector);
} else {
aValue = selector(a);
bValue = selector(b);
}
return rows.slice(0).sort((a: T, b: T) => {
let aValue;
let bValue;

if (typeof selector === 'string') {
aValue = parseSelector(a, selector);
bValue = parseSelector(b, selector);
} else {
aValue = selector(a);
bValue = selector(b);
}

if (direction === 'asc') {
if (aValue < bValue) {
return -1;
}
if (direction === 'asc') {
if (aValue < bValue) {
return -1;
}

if (aValue > bValue) {
return 1;
}
if (aValue > bValue) {
return 1;
}
}

if (direction === 'desc') {
if (aValue > bValue) {
return -1;
}
if (direction === 'desc') {
if (aValue > bValue) {
return -1;
}

if (aValue < bValue) {
return 1;
}
if (aValue < bValue) {
return 1;
}
}

return 0;
})
.slice(0);
return 0;
});
}

// TODO: string based selectors will be removed in v8
Expand Down

0 comments on commit f4e6325

Please sign in to comment.