From 157d7f2a856a32fcccd0c627a5be9ee7f95d0622 Mon Sep 17 00:00:00 2001 From: Nicola Good Date: Sat, 2 Jan 2021 15:39:13 +0100 Subject: [PATCH] Adding the ability to sort Date strings --- package.json | 1 + src/DataTable.vue | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 2816ab0..5fb2142 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "dependencies": { "fuse.js": "^2.6.2", "html-webpack-plugin": "^3.2.0", + "moment": "^2.29.1", "tb-skeleton": "^0.3.5", "vue": "^2.6.12" }, diff --git a/src/DataTable.vue b/src/DataTable.vue index 38d9f72..6cc770a 100644 --- a/src/DataTable.vue +++ b/src/DataTable.vue @@ -148,6 +148,7 @@ import 'tb-skeleton/dist/skeleton.css'; import Fuse from 'fuse.js'; + import moment from 'moment'; import locales from './locales'; import { TbSkeleton } from 'tb-skeleton'; @@ -504,9 +505,13 @@ const cook = x => { x = this.collect(x, this.columns[this.sortColumn].field); if (typeof(x) === 'string') { - x = x.toLowerCase(); - if (this.columns[this.sortColumn].numeric) - x = x.indexOf('.') >= 0 ? parseFloat(x) : parseInt(x); + if (moment(x).isValid()) { + x = moment(x); + } else { + x = x.toLowerCase(); + if (this.columns[this.sortColumn].numeric) + x = x.indexOf('.') >= 0 ? parseFloat(x) : parseInt(x); + } } return x; };