File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ import AdvancedCourseFilters from "../../components/course/AdvancedCourseFilters
110110const { t } = useI18n ()
111111const sortField = ref (" title" )
112112
113+ const natural = new Intl.Collator (undefined , { numeric: true , sensitivity: " base" })
113114const router = useRouter ()
114115const securityStore = useSecurityStore ()
115116const platformConfigStore = usePlatformConfig ()
@@ -451,13 +452,23 @@ const visibleCoursesBase = computed(() => {
451452 valB = b .extra_fields ? .[field] ?? " "
452453 }
453454
454- if (typeof valA === " string" ) valA = valA .toLowerCase ()
455- if (typeof valB === " string" ) valB = valB .toLowerCase ()
456-
457- if (valA < valB) return - 1 * order
458- if (valA > valB) return 1 * order
459- return 0
455+ // Natural compare for strings; numeric compare otherwise
456+ const cmp =
457+ typeof valA === " string" || typeof valB === " string"
458+ ? natural .compare (String (valA), String (valB))
459+ : valA < valB
460+ ? - 1
461+ : valA > valB
462+ ? 1
463+ : 0
464+
465+ return (
466+ cmp *
467+ (typeof order === " number" ? (order >= 0 ? 1 : - 1 ) : String (order).toLowerCase ().startsWith (" desc" ) ? - 1 : 1 )
468+ )
460469 })
470+ } else {
471+ list = list .slice ().sort ((a , b ) => natural .compare (String (a .title ?? " " ), String (b .title ?? " " )))
461472 }
462473
463474 return list
You can’t perform that action at this time.
0 commit comments