Fix table date type column sorting (#6134)

This commit is contained in:
Vicky Bansal 2021-08-16 19:07:30 +05:30 committed by GitHub
parent 25a6590b47
commit 82722e5a38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -240,7 +240,7 @@ export default {
const column = columns.find((column) => column.id === sortedColumn);
const columnType =
column && column.columnType ? column.columnType : "text";
const inputFormat = column.inputFormat;
sortedTableData = derivedTableData.sort((a, b) => {
if (
_.isPlainObject(a) &&
@ -260,10 +260,14 @@ export default {
case "date":
try {
return sortOrder
? moment(a[sortedColumn]).isAfter(b[sortedColumn])
? moment(a[sortedColumn], inputFormat).isAfter(
moment(b[sortedColumn], inputFormat),
)
? 1
: -1
: moment(b[sortedColumn]).isAfter(a[sortedColumn])
: moment(b[sortedColumn], inputFormat).isAfter(
moment(a[sortedColumn], inputFormat),
)
? 1
: -1;
} catch (e) {