Skip to content

Commit

Permalink
fix: dates using default comparator for sorting (#591)
Browse files Browse the repository at this point in the history
* fix: dates are now using default comparator

---------

Co-authored-by: Benjamin <[email protected]>
  • Loading branch information
markuczy and BenjaminPabst authored Nov 12, 2024
1 parent b0bd219 commit 2940931
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,28 @@ export class DataSortBase {
if (!clientSideSorting || sortColumn === '') {
return [items, filters, sortColumn, sortDirection, translations]
}
let translatedColValues: Record<string, string> = 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<string, string>
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,
Expand Down

0 comments on commit 2940931

Please sign in to comment.