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; };