I would like to sort antd table by a Date
column.
Trying to sort like sorter: (a, b) => new Date(a) - new Date(b)
What I've been doing so far here and failed to solve it.
Simply define a new sorting routine in utils/sorter. js , add it to the Sorter “enum,” and use it in your sorter prop for any column that needs it. You can check out the CodeSandbox for this tutorial to play around with the result.
You can make use of the responsive property on the column that you want to control for screen sizes. Just add a From To column with a custom render function, and set the responsive property on that column to only show on xs screens. The From and To columns will have the responsive property set to show on md and above.
Rows can be selectable by making first column as a selectable column. You can use rowSelection.type to set selection type. Default is checkbox . selection happens when clicking checkbox by default.
Try this one. This will automatically sort by date ASC to DESC, DESC to ASC as you click the column header. You need to install moment
imports:
import moment from 'moment';
Sorter:
sorter: (a, b) => moment(a.date).unix() - moment(b.date).unix()
a
,b
are table records, so you need new Date(a.date) - new Date(b.date)
:
{
title: 'Date',
dataIndex: 'date',
key: 'date',
sorter: (a, b) => new Date(a.date) - new Date(b.date)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With