Untitled
unknown
typescript
a year ago
743 B
10
Indexable
export function arraySort<T>(array: T[], oDataConfig: ODataConfig) {
const sorts = oDataConfig.Sorts.sort((a, b) => b.Priority - a.Priority);
return sorts.reduce(
(sortedArray, sort) => {
return sortedArray.sort((a, b) => {
const valueA = a[sort.PropertyName as keyof T];
const valueB = b[sort.PropertyName as keyof T];
if (valueA < valueB) {
return sort.Direction === ODataSortingDirection.Descending ? -1 : 1;
} else if (valueA > valueB) {
return sort.Direction === ODataSortingDirection.Ascending ? 1 : -1;
}
return 0;
});
},
[...array],
);
}Editor is loading...
Leave a Comment