我有一个使用Vue Tables 2中的v-client-table方法的自定义组件。该表有两列,其中一列是日期时间列(格式:MM / DD / YYYY h:mm A)。我把它作为可排序的,但它不能根据时间准确排序。输出如下所示:
如您所见,它从下午12:09到12:30。不幸的是,这个日期/时间格式是必需的。
问题:有没有办法将momentjs合并到配置中以使其正确排序(不使用client-side-sorting documentation中显示的过滤器)?
以下是数据和选项:
export const content = {
state: {
columns: ['callDateTime', 'explanation'],
tableData: [
{ callDateTime: '10/13/2017 10:09 AM', explanation: "Lorem ipsum dolor sit amet, consectetur adipiscing elit." },
{ callDateTime: '10/13/2017 12:30 AM', explanation: "Lorem ipsum dolor" },
{ callDateTime: '10/13/2017 12:09 PM', explanation: "Lorem ipsum dolor sit amet },
{ callDateTime: '10/13/2017 1:15 PM', explanation: "Ut a fringilla mauris" },
{ callDateTime: '10/13/2017 1:30 PM', explanation: "Lorem ipsum dolor" }
],
options: {
headings: {
'callDateTime': 'Call Date/Time',
'explanation': 'Interaction Notes',
},
filterable: 'false',
sortable: 'callDateTime',
orderBy: { column: 'callDateTime' },
pagination: {
edge: false,
dropdown: false,
chunk: 1
},
sortIcon: {
down: 'arrow arrow-down',
up: 'arrow arrow-up'
},
perPage: '10',
texts: {
count: ''
}
}
}
}
答案 0 :(得分:2)
使用{/ 3}}可以使用此
customSorting: {
callDateTime: function (ascending) {
return function (a, b) {
let dateA = new Date(a.callDateTime);
let dateB = new Date(b.callDateTime);
if (ascending)
return dateA >= dateB ? 1 : -1;
return dateA <= dateB ? 1 : -1;
}
}
}