Skip to content

Commit 2fc7853

Browse files
fixes sort
1 parent e5b3963 commit 2fc7853

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/components/tables/CippTable.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,27 +79,23 @@ FilterComponent.propTypes = {
7979
filterlist: PropTypes.arrayOf(PropTypes.object),
8080
onFilterPreset: PropTypes.func,
8181
}
82+
const compareValues = (a, b) => {
83+
if (a === null) return 1
84+
if (b === null) return -1
85+
if (typeof a === 'number' && typeof b === 'number') return a - b
86+
if (typeof a === 'boolean' && typeof b === 'boolean') return a === b ? 0 : a ? -1 : 1
87+
return String(a).localeCompare(String(b), 'en', { numeric: true })
88+
}
8289

8390
const customSort = (rows, selector, direction) => {
8491
return rows.sort((a, b) => {
85-
// use the selector to resolve your field names by passing the sort comparitors
86-
let aField
87-
let bField
88-
89-
aField = selector(a)
90-
bField = selector(b)
91-
92-
let comparison = 0
93-
94-
if (aField?.toString().localeCompare(bField, 'en', { numeric: true }) > 0) {
95-
comparison = 1
96-
} else if (aField?.toString().localeCompare(bField, 'en', { numeric: true }) < 0) {
97-
comparison = -1
98-
}
99-
92+
let aField = selector(a)
93+
let bField = selector(b)
94+
let comparison = compareValues(aField, bField)
10095
return direction === 'desc' ? comparison * -1 : comparison
10196
})
10297
}
98+
10399
export default function CippTable({
104100
data,
105101
isFetching = false,

0 commit comments

Comments
 (0)