使用Moment.js库来格式化日期时间字符串,并使用自定义排序函数来对日期时间列进行排序。
示例代码:
import * as moment from 'moment';
tableOptions: DataTables.Options = { // ... columns: [ // ... { title: '时间', data: 'datetime', type: 'date', render: (data: any): string => { return moment(data).format('YYYY-MM-DD HH:mm:ss'); }, sortMethod: (a: any, b: any): number => { let aMoment = moment(a, 'YYYY-MM-DD HH:mm:ss'); let bMoment = moment(b, 'YYYY-MM-DD HH:mm:ss'); return aMoment.isBefore(bMoment) ? -1 : aMoment.isAfter(bMoment) ? 1 : 0; } } ] };