Search code examples
javascriptreactjsantd

How to sort ant table column by date?


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.


Solution

  • 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()