Date column sorts alphabetically instead of chronologically in DataTables
0 reputation · 25 Apr 2026, 15:15 UTC
Sorted dates drift out of order once regional formatting is applied
The goal is a DataTables 1.13+/2.x table that displays UTC timestamps converted to each viewer's regional time zone while the date column still sorts chronologically. DataTables performs no native date parsing — cell values are handled as strings — so a column holding formatted local dates can fall back to lexicographic ordering, which scatters non-ISO formats out of sequence.
Two documented mechanisms compete for this role. The datetime-moment plugin teaches DataTables to parse and format dates through Moment.js, while orthogonal data — a render function returning a display string alongside a hidden sort value, or a data-order attribute — keeps the raw timestamp for ordering. The regional conversion itself must happen during data transformation before the cell renderer runs, and doing it client-side makes the output depend on the visitor's system clock and locale being configured correctly. Moment.js also adds bundle weight and is in maintenance mode, which keeps Luxon in the comparison.
The unresolved decision is which layer should own conversion and ordering:
- Does the datetime-moment plugin order rows from the original source value, or must orthogonal data or data-order still be supplied to prevent alphabetical sorting of the formatted output?
- Should the UTC-to-local conversion run inside the column's render function or earlier in the data pipeline, given the misconfigured system clock caveat?