Sort dates

In your data, you might have date or date-string fields whose format does not allow natural sorting.

// "MM/dd/yyyy hh:mm:ss a" - en_US
const data = [
    { user: 'John Doe',             created_at: '12/01/2024 11:04:23 AM' },
    { user: 'Tobie Vint',           created_at: '09/30/2020 01:43:06 PM' },
    { user: 'Zacharias Cerman',     created_at: '04/26/2023 05:02:21 PM' },
    { user: 'Gérianna Bunn',        created_at: '03/13/2021 07:58:33 AM' },
    { user: 'Bee Saurin',           created_at: '11/08/2019 03:21:54 PM' },
    { user: 'Méyère Granulette',    created_at: '07/27/2022 08:12:16 PM' },
    { user: 'Jane Doe',             created_at: '01/18/2017 11:38:47 AM' },
    { user: 'Michel Trapu',         created_at: '04/02/2025 04:19:46 PM' },
]

Just like nested props, you can refine these fields by using a callback to return a YYYY-MM-DDTHH:mm:ss.sssZ format (ISO String).

const field = (row) => new Date(row.created_at).toISOString()

Example

const sort = table.createSort(row => new Date(row.created_at).toISOString())
user
created_at
John Doe12/01/2024 11:04:23 AM
Tobie Vint09/30/2020 01:43:06 PM
Zacharias Cerman04/26/2023 05:02:21 PM
Gérianna Bunn03/13/2021 07:58:33 AM
Bee Saurin11/08/2019 03:21:54 PM
Méyère Granulette07/27/2022 08:12:16 PM
Jane Doe01/18/2017 11:38:47 AM
Michel Trapu04/02/2025 04:19:46 PM