@@ -79,27 +79,23 @@ FilterComponent.propTypes = {
79
79
filterlist : PropTypes . arrayOf ( PropTypes . object ) ,
80
80
onFilterPreset : PropTypes . func ,
81
81
}
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
+ }
82
89
83
90
const customSort = ( rows , selector , direction ) => {
84
91
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 )
100
95
return direction === 'desc' ? comparison * - 1 : comparison
101
96
} )
102
97
}
98
+
103
99
export default function CippTable ( {
104
100
data,
105
101
isFetching = false ,
0 commit comments