Files
WebControlCenter/src/utility/sort.ts
2025-09-04 20:25:15 -04:00

21 lines
599 B
TypeScript

/**
* Copyright 2024 Phenix Real Time Solutions, Inc. Confidential and Proprietary. All Rights Reserved.
*/
import {DirectionType} from 'interfaces/tableProps';
import {DataValueType} from 'components/table';
export const compare = (a: Record<string, DataValueType>, b: Record<string, DataValueType>, direction: DirectionType, propName: string): number => {
if (a && b) {
const isDesc = direction === DirectionType.Desc;
if (a[propName] < b[propName]) {
return isDesc ? -1 : 1;
} else if (a[propName] > b[propName]) {
return isDesc ? 1 : -1;
}
}
return 0;
};