@@ -4,7 +4,6 @@ import { formatSiret } from "../../../../../helpers/utils";
4
4
import { formatUpperCase } from "../../../../../utils/entreprise/entreprise" ;
5
5
import { getCodePostal } from "../../../../../utils/establishment/establishment" ;
6
6
7
- // Suppose this function is imported or defined
8
7
export const getCity = ( marche ) =>
9
8
marche ?. etablissement ?. libellecommuneetablissement ||
10
9
marche ?. etablissement ?. libellecommune2etablissement ;
@@ -25,22 +24,39 @@ export const useSortableData = (items, config = null) => {
25
24
if ( sortConfig . key === "city" ) {
26
25
aValue = getCodePostal ( a ?. etablissement ) ; // Retrieve city using getCity
27
26
bValue = getCodePostal ( b ?. etablissement ) ;
28
- console . log ( bValue ) ;
29
27
} else if ( sortConfig . key === "acheteur" ) {
30
28
aValue = getAcheteur ( a ) ;
31
29
bValue = getAcheteur ( b ) ;
30
+ } else if (
31
+ sortConfig . key === "montant" ||
32
+ sortConfig . key === "dureeMois"
33
+ ) {
34
+ // Convertir 'montant' en nombre
35
+ aValue = parseFloat ( a [ sortConfig . key ] ) ;
36
+ bValue = parseFloat ( b [ sortConfig . key ] ) ;
32
37
} else {
33
38
aValue = a [ sortConfig . key ] ;
34
39
bValue = b [ sortConfig . key ] ;
35
40
}
36
41
37
- if ( aValue < bValue ) {
38
- return sortConfig . direction === "ascending" ? - 1 : 1 ;
39
- }
40
- if ( aValue > bValue ) {
41
- return sortConfig . direction === "ascending" ? 1 : - 1 ;
42
+ // Gérer les valeurs nulles ou indéfinies
43
+ if ( aValue == null ) return 1 ;
44
+ if ( bValue == null ) return - 1 ;
45
+
46
+ // Comparaison appropriée en fonction du type
47
+ if ( typeof aValue === "number" && typeof bValue === "number" ) {
48
+ return sortConfig . direction === "ascending"
49
+ ? aValue - bValue
50
+ : bValue - aValue ;
51
+ } else {
52
+ if ( aValue < bValue ) {
53
+ return sortConfig . direction === "ascending" ? - 1 : 1 ;
54
+ }
55
+ if ( aValue > bValue ) {
56
+ return sortConfig . direction === "ascending" ? 1 : - 1 ;
57
+ }
58
+ return 0 ;
42
59
}
43
- return 0 ;
44
60
} ) ;
45
61
}
46
62
return sortableItems ;
0 commit comments