Skip to content

Commit 43adae8

Browse files
Aramis13johnleider
authored andcommitted
fix(VDataTable): adjust filter & sort functions to use Intl.Collator (#7805)
* Adjustment for filter & sort functions to use Intl.Collator * Adjustment for filter & sort functions to use Intl.Collator * Bug fix for inner sort loop * Add unknown before PropValidator * Discard changes * Discard changes * Discard changes defaultFilter function * Initialize collator outside of loop fixes #3672 fixes #4622
1 parent 8c0315d commit 43adae8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/vuetify/src/util/helpers.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ export function sortItems (
387387
) {
388388
if (sortBy === null || !sortBy.length) return items
389389

390+
const numericCollator = new Intl.Collator(locale, { numeric: true, usage: 'sort' })
391+
const stringCollator = new Intl.Collator(locale, { sensitivity: 'accent', usage: 'sort' })
392+
390393
return items.sort((a, b) => {
391394
for (let i = 0; i < sortBy.length; i++) {
392395
const sortKey = sortBy[i]
@@ -414,11 +417,8 @@ export function sortItems (
414417
[sortA, sortB] = [sortA, sortB].map(s => (s || '').toString().toLocaleLowerCase())
415418

416419
if (sortA !== sortB) {
417-
const sortResult = (!isNaN(sortA) && !isNaN(sortB))
418-
? Number(sortA) - Number(sortB)
419-
: sortA.localeCompare(sortB, locale)
420-
421-
if (sortResult) return sortResult
420+
if (!isNaN(sortA) && !isNaN(sortB)) return numericCollator.compare(sortA, sortB)
421+
return stringCollator.compare(sortA, sortB)
422422
}
423423
}
424424

0 commit comments

Comments
 (0)