Add new sort everywhere needed, update API docs

pull/4570/head
FlipWarthog 2023-10-06 18:59:00 -04:00
parent 4d6a272795
commit f9360b8ade
6 changed files with 24 additions and 48 deletions

View File

@ -101,7 +101,7 @@ import ChevronLeftIcon from 'primevue/icons/chevronleft';
import ChevronRightIcon from 'primevue/icons/chevronright';
import ChevronUpIcon from 'primevue/icons/chevronup';
import Ripple from 'primevue/ripple';
import { DomHandler, UniqueComponentId } from 'primevue/utils';
import { DomHandler, UniqueComponentId, ObjectUtils } from 'primevue/utils';
import BaseCarousel from './BaseCarousel.vue';
export default {
@ -553,15 +553,8 @@ export default {
_responsiveOptions.sort((data1, data2) => {
const value1 = data1.breakpoint;
const value2 = data2.breakpoint;
let result = null;
if (value1 == null && value2 != null) result = -1;
else if (value1 != null && value2 == null) result = 1;
else if (value1 == null && value2 == null) result = 0;
else if (typeof value1 === 'string' && typeof value2 === 'string') result = comparer(value1, value2);
else result = value1 < value2 ? -1 : value1 > value2 ? 1 : 0;
return -1 * result;
return ObjectUtils.sort(value1, value2, -1, comparer);
});
for (let i = 0; i < _responsiveOptions.length; i++) {

View File

@ -887,6 +887,11 @@ export interface DataTableProps {
* Order to sort the data by default.
*/
sortOrder?: number | undefined;
/**
* Determines how null values are sorted.
* @defaultValue 1
*/
nullSortOrder?: number;
/**
* Default sort order of an unsorted column.
* @defaultValue 1

View File

@ -115,15 +115,8 @@ export default {
value.sort((data1, data2) => {
let value1 = ObjectUtils.resolveFieldData(data1, this.sortField);
let value2 = ObjectUtils.resolveFieldData(data2, this.sortField);
let result = null;
if (value1 == null && value2 != null) result = -1;
else if (value1 != null && value2 == null) result = 1;
else if (value1 == null && value2 == null) result = 0;
else if (typeof value1 === 'string' && typeof value2 === 'string') result = comparer(value1, value2);
else result = value1 < value2 ? -1 : value1 > value2 ? 1 : 0;
return this.sortOrder * result;
return ObjectUtils.sort(value1, value2, this.sortOrder, comparer);
});
return value;

View File

@ -68,7 +68,7 @@ import ChevronLeftIcon from 'primevue/icons/chevronleft';
import ChevronRightIcon from 'primevue/icons/chevronright';
import ChevronUpIcon from 'primevue/icons/chevronup';
import Ripple from 'primevue/ripple';
import { DomHandler } from 'primevue/utils';
import { DomHandler, ObjectUtils } from 'primevue/utils';
export default {
name: 'GalleriaThumbnails',
@ -443,15 +443,8 @@ export default {
this.sortedResponsiveOptions.sort((data1, data2) => {
const value1 = data1.breakpoint;
const value2 = data2.breakpoint;
let result = null;
if (value1 == null && value2 != null) result = -1;
else if (value1 != null && value2 == null) result = 1;
else if (value1 == null && value2 == null) result = 0;
else if (typeof value1 === 'string' && typeof value2 === 'string') result = comparer(value1, value2);
else result = value1 < value2 ? -1 : value1 > value2 ? 1 : 0;
return -1 * result;
return ObjectUtils.sort(value1, value2, -1, comparer);
});
for (let i = 0; i < this.sortedResponsiveOptions.length; i++) {

View File

@ -434,15 +434,8 @@ export default {
_nodes.sort((node1, node2) => {
const value1 = ObjectUtils.resolveFieldData(node1.data, this.d_sortField);
const value2 = ObjectUtils.resolveFieldData(node2.data, this.d_sortField);
let result = null;
if (value1 == null && value2 != null) result = -1;
else if (value1 != null && value2 == null) result = 1;
else if (value1 == null && value2 == null) result = 0;
else if (typeof value1 === 'string' && typeof value2 === 'string') result = comparer(value1, value2);
else result = value1 < value2 ? -1 : value1 > value2 ? 1 : 0;
return this.d_sortOrder * result;
return ObjectUtils.sort(value1, value2, this.d_sortOrder, comparer);
});
return _nodes;
@ -462,22 +455,13 @@ 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);
let result = null;
const comparer = ObjectUtils.localeComparator();
if (value1 == null && value2 != null) result = -1;
else if (value1 != null && value2 == null) result = 1;
else if (value1 == null && value2 == null) result = 0;
else {
if (value1 === value2) {
return this.d_multiSortMeta.length - 1 > index ? this.multisortField(node1, node2, index + 1) : 0;
} else {
if ((typeof value1 === 'string' || value1 instanceof String) && (typeof value2 === 'string' || value2 instanceof String))
return this.d_multiSortMeta[index].order * ObjectUtils.localeComparator().compare(value1, value2);
else result = value1 < value2 ? -1 : 1;
}
if (value1 === value2) {
return this.d_multiSortMeta.length - 1 > index ? this.multisortField(node1, node2, index + 1) : 0;
}
return this.d_multiSortMeta[index].order * result;
return ObjectUtils.sort(value1, value2, this.d_multiSortMeta[index].order, comparer);
},
filter(value) {
let filteredNodes = [];

View File

@ -18854,6 +18854,14 @@
"default": "",
"description": "Order to sort the data by default."
},
{
"name": "nullSortOrder",
"optional": true,
"readonly": false,
"type": "number",
"default": "1",
"description": "Determines how null values are sorted."
},
{
"name": "defaultSortOrder",
"optional": true,
@ -55561,4 +55569,4 @@
}
}
}
}
}