diff --git a/libs/angular-accelerator/src/lib/components/data-sort-base/data-sort-base.ts b/libs/angular-accelerator/src/lib/components/data-sort-base/data-sort-base.ts index 3014e5da..42856df1 100644 --- a/libs/angular-accelerator/src/lib/components/data-sort-base/data-sort-base.ts +++ b/libs/angular-accelerator/src/lib/components/data-sort-base/data-sort-base.ts @@ -110,17 +110,28 @@ export class DataSortBase { if (!clientSideSorting || sortColumn === '') { return [items, filters, sortColumn, sortDirection, translations] } - let translatedColValues: Record = Object.fromEntries( - items.map((i) => [ - ObjectUtils.resolveFieldData(i, sortColumn)?.toString(), - ObjectUtils.resolveFieldData(i, sortColumn)?.toString(), - ]) - ) - if (columns.find((h) => h.id === sortColumn)?.columnType === ColumnType.TRANSLATION_KEY) { - translatedColValues = translations[sortColumn] + const column = columns.find((h) => h.id === sortColumn) + let colValues: Record + if (column?.columnType === ColumnType.DATE || column?.columnType === ColumnType.RELATIVE_DATE) { + colValues = Object.fromEntries( + items.map((i) => [ + ObjectUtils.resolveFieldData(i, sortColumn) as Date, + ObjectUtils.resolveFieldData(i, sortColumn) as Date, + ]) + ) + } else { + colValues = Object.fromEntries( + items.map((i) => [ + ObjectUtils.resolveFieldData(i, sortColumn)?.toString(), + ObjectUtils.resolveFieldData(i, sortColumn)?.toString(), + ]) + ) + } + if (column?.columnType === ColumnType.TRANSLATION_KEY) { + colValues = translations[sortColumn] } return [ - [...items].sort(this.createCompareFunction(translatedColValues, sortColumn, sortDirection)), + [...items].sort(this.createCompareFunction(colValues, sortColumn, sortDirection)), filters, sortColumn, sortDirection,