Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4623 - DataTable: Wrong alphabetical sorting for Norwegian #4628

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/lib/calendar/Calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2669,7 +2669,7 @@ export default {
let innerHTML = '';

if (this.responsiveOptions) {
const comparer = ObjectUtils.localeComparator();
const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode);
let responsiveOptions = [...this.responsiveOptions].filter((o) => !!(o.breakpoint && o.numMonths)).sort((o1, o2) => -1 * comparer(o1.breakpoint, o2.breakpoint));

for (let i = 0; i < responsiveOptions.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion components/lib/carousel/Carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ export default {

if (this.responsiveOptions && !this.isUnstyled) {
let _responsiveOptions = [...this.responsiveOptions];
const comparer = ObjectUtils.localeComparator();
const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode);

_responsiveOptions.sort((data1, data2) => {
const value1 = data1.breakpoint;
Expand Down
1 change: 1 addition & 0 deletions components/lib/config/PrimeVue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import { VirtualScrollerPassThroughOptions } from '../virtualscroller';
export interface PrimeVueConfiguration {
ripple?: boolean;
inputStyle?: string;
localeCode?: string;
locale?: PrimeVueLocaleOptions;
filterMatchModeOptions?: any;
zIndex?: PrimeVueZIndexOptions;
Expand Down
1 change: 1 addition & 0 deletions components/lib/config/PrimeVue.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { inject, reactive } from 'vue';
export const defaultOptions = {
ripple: false,
inputStyle: 'outlined',
localeCode: 'en',
locale: {
startsWith: 'Starts with',
contains: 'Contains',
Expand Down
4 changes: 2 additions & 2 deletions components/lib/datatable/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ export default {
resolvedFieldData.set(item, ObjectUtils.resolveFieldData(item, this.d_sortField));
}

const comparer = ObjectUtils.localeComparator();
const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode);

data.sort((data1, data2) => {
let value1 = resolvedFieldData.get(data1);
Expand Down Expand Up @@ -575,7 +575,7 @@ export default {
multisortField(data1, data2, index) {
const value1 = ObjectUtils.resolveFieldData(data1, this.d_multiSortMeta[index].field);
const value2 = ObjectUtils.resolveFieldData(data2, this.d_multiSortMeta[index].field);
const comparer = ObjectUtils.localeComparator();
const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode);

if (value1 === value2) {
return this.d_multiSortMeta.length - 1 > index ? this.multisortField(data1, data2, index + 1) : 0;
Expand Down
2 changes: 1 addition & 1 deletion components/lib/dataview/DataView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default {
sort() {
if (this.value) {
const value = [...this.value];
const comparer = ObjectUtils.localeComparator();
const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode);

value.sort((data1, data2) => {
let value1 = ObjectUtils.resolveFieldData(data1, this.sortField);
Expand Down
2 changes: 1 addition & 1 deletion components/lib/galleria/GalleriaThumbnails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ export default {

if (this.responsiveOptions && !this.isUnstyled) {
this.sortedResponsiveOptions = [...this.responsiveOptions];
const comparer = ObjectUtils.localeComparator();
const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode);

this.sortedResponsiveOptions.sort((data1, data2) => {
const value1 = data1.breakpoint;
Expand Down
4 changes: 2 additions & 2 deletions components/lib/treetable/TreeTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ export default {
},
sortNodesSingle(nodes) {
let _nodes = [...nodes];
const comparer = ObjectUtils.localeComparator();
const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode);

_nodes.sort((node1, node2) => {
const value1 = ObjectUtils.resolveFieldData(node1.data, this.d_sortField);
Expand All @@ -455,7 +455,7 @@ export default {
multisortField(node1, node2, index) {
const value1 = ObjectUtils.resolveFieldData(node1.data, this.d_multiSortMeta[index].field);
const value2 = ObjectUtils.resolveFieldData(node2.data, this.d_multiSortMeta[index].field);
const comparer = ObjectUtils.localeComparator();
const comparer = ObjectUtils.localeComparator(this.$primevue.config.localeCode);

if (value1 === value2) {
return this.d_multiSortMeta.length - 1 > index ? this.multisortField(node1, node2, index + 1) : 0;
Expand Down
4 changes: 2 additions & 2 deletions components/lib/utils/ObjectUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ export default {
return result;
},

localeComparator() {
localeComparator(localeCode) {
//performance gain using Int.Collator. It is not recommended to use localeCompare against large arrays.
return new Intl.Collator(undefined, { numeric: true }).compare;
return new Intl.Collator(localeCode, { numeric: true }).compare;
},

nestedKeys(obj = {}, parentKey = '') {
Expand Down
7 changes: 7 additions & 0 deletions doc/common/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -14005,6 +14005,13 @@
"type": "string",
"default": ""
},
{
"name": "localeCode",
"optional": true,
"readonly": false,
"type": "string",
"default": ""
},
{
"name": "locale",
"optional": true,
Expand Down
2 changes: 2 additions & 0 deletions doc/configuration/locale/SetLocaleDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default {
code1: {
basic: `
app.use(PrimeVue, {
localeCode: 'es',
locale: {
accept: 'Aceptar',
reject: 'Rechazar',
Expand All @@ -34,6 +35,7 @@ export default defineComponent({
setup() {
const changeToSpanish = () => {
const primevue = usePrimeVue();
primevue.config.localeCode = "es";
primevue.config.locale.accept = "Aceptar";
primevue.config.locale.reject = "Rechazar";
}
Expand Down
Loading