[英]Antd table, how to sort by date including the whole timestamp?
I have this item我有这个项目
const data: Item[] = [
{
key: 1,
name: 'John Brown',
date: moment('10-10-2019').format('L'),
address: 'New York No. 1 Lake Park',
},
{
key: 2,
name: 'Joe Black',
date: moment('11-10-2019').format('L'),
address: 'London No. 1 Lake Park',
},
{
key: 3,
name: 'Jim Green',
date: moment('7-10-2019').format('L'),
address: 'Sidney No. 1 Lake Park',
},
{
key: 4,
name: 'Jim Red',
date: moment('8-10-2019 8:00 PM').format('L'),
// date: moment('8-10-2019 8:00 PM').format('MMMM Do YYYY, h:mm:ss a'),
address: 'London No. 2 Lake Park',
},
];
If I use that data for "date" , and I use the following sorter it works fine如果我将该数据用于“日期”,并且我使用以下排序器,则它可以正常工作
sorter: (a, b) => moment(a.date).unix() - moment(b.date).unix()
But I want the data to be a bit more complex, like this但我希望数据更复杂一点,像这样
date: moment('8-10-2019 8:00 PM').format('MMMM Do YYYY, h:mm:ss a')
Which evaluates to August 10th 2019, 8:00:00 pm
其中评估为
August 10th 2019, 8:00:00 pm
Problem is, that I can't sort that data with the above sorter.问题是,我无法使用上述排序器对数据进行排序。 How could I do it?
我怎么能做到?
Try this sorter:试试这个排序器:
sorter: (a, b) =>
new Date(moment(a.date, "MMMM Do YYYY, h:mm:ss a").format("LLL")) -
new Date(moment(b.date, "MMMM Do YYYY, h:mm:ss a").format("LLL")),
Also take note that there's a deprecate warning that you are using a value (your provided date) that is not in a recognized RFC2822 or ISO format.另请注意,有一个弃用警告,表明您使用的值(您提供的日期)不是公认的 RFC2822 或 ISO 格式。 You can check a valid format on
moment
documentation.您可以在
moment
文档中检查有效格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.