bugfixing type rating

This commit is contained in:
MuslemRahimi 2024-11-26 21:09:50 +01:00
parent 1d0e18e56f
commit 2fa6443506

View File

@ -482,12 +482,29 @@
valueA = new Date(a[key]); valueA = new Date(a[key]);
valueB = new Date(b[key]); valueB = new Date(b[key]);
break; break;
case "rating":
case "string": case "string":
valueA = a[key]?.toUpperCase(); // Retrieve values
valueB = b[key]?.toUpperCase(); valueA = a[key];
valueB = b[key];
// Handle null or undefined values, always placing them at the bottom
if (valueA == null && valueB == null) {
return 0; // Both are null/undefined, no need to change the order
} else if (valueA == null) {
return 1; // null goes to the bottom
} else if (valueB == null) {
return -1; // null goes to the bottom
}
// Convert the values to uppercase for case-insensitive comparison
valueA = valueA?.toUpperCase();
valueB = valueB?.toUpperCase();
// Perform the sorting based on ascending or descending order
return sortOrder === "asc" return sortOrder === "asc"
? valueA.localeCompare(valueB) ? valueA?.localeCompare(valueB)
: valueB.localeCompare(valueA); : valueB?.localeCompare(valueA);
case "number": case "number":
default: default:
valueA = parseFloat(a[key]); valueA = parseFloat(a[key]);