Skip to content

Commit 36f4ed5

Browse files
authored
fix: fix marche publiques sort (#356)
1 parent 6fb2557 commit 36f4ed5

File tree

1 file changed

+24
-8
lines changed
  • src/client/src/components/DataSheets/Sections/SharedComponents/NonBorderedTable

1 file changed

+24
-8
lines changed

src/client/src/components/DataSheets/Sections/SharedComponents/NonBorderedTable/hooks.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { formatSiret } from "../../../../../helpers/utils";
44
import { formatUpperCase } from "../../../../../utils/entreprise/entreprise";
55
import { getCodePostal } from "../../../../../utils/establishment/establishment";
66

7-
// Suppose this function is imported or defined
87
export const getCity = (marche) =>
98
marche?.etablissement?.libellecommuneetablissement ||
109
marche?.etablissement?.libellecommune2etablissement;
@@ -25,22 +24,39 @@ export const useSortableData = (items, config = null) => {
2524
if (sortConfig.key === "city") {
2625
aValue = getCodePostal(a?.etablissement); // Retrieve city using getCity
2726
bValue = getCodePostal(b?.etablissement);
28-
console.log(bValue);
2927
} else if (sortConfig.key === "acheteur") {
3028
aValue = getAcheteur(a);
3129
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]);
3237
} else {
3338
aValue = a[sortConfig.key];
3439
bValue = b[sortConfig.key];
3540
}
3641

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;
4259
}
43-
return 0;
4460
});
4561
}
4662
return sortableItems;

0 commit comments

Comments
 (0)