table icon indicating copy to clipboard operation
table copied to clipboard

Date Sorting

Open mBromige opened this issue 7 years ago • 3 comments

Hello, I am using the 'react table' and 'moment' to format dates in the column I am trying to sort. However, although I have set the accessor like so: { Header: 'Date', id: 'date', accessor: row => moment(row.start).format('lll'), }, The column is still sorting as a literal string. I have been looking through the many solutions suggested on this repo, but none have seemed to work for me. I welcome any suggestions to sorting date. Many thanks in advance!

mBromige avatar Mar 27 '19 11:03 mBromige

Please repost this question in the https://spectrum.chat/react-table forum. Thanks!

tannerlinsley avatar Mar 27 '19 11:03 tannerlinsley

@mBromige did you receive any useful answer?

baba43 avatar Aug 25 '19 10:08 baba43

This is mrBromige anwser on spectrum:

I have found a solution, if experiencing the same issues:

4:06pm

{ Header: 'Date', id: 'date', accessor: row => moment(row.start).format('x'), Cell: row => moment(row.original.start).format('lll'), } 4:07pm Sort the accessor by timestamp and then format it to your desired moment date style

Matar91 avatar Jun 08 '20 09:06 Matar91