Sorting dates in columns

Sorting dates in columns

sjw01sjw01 Posts: 44Questions: 20Answers: 1

I see this:

From what I understand, effectively a date column can only be sorted provided they are displayed as YYYY-MM-DD?

Is that right? The "limited set of dates" link to in the option shows YYYY-MM-DD ... YYYY/MM/DD

Which effectively is just sorting numerically and doesn't really require the field type to be a date? If I put the date into a format that allows sorting numerically, there is no point to defining a column type = date?

As can be seen, - all date columns are displayed DD/MM/YY and don't sort

Am I misinterpreting the doco? Displaying the date as YYYY-MM-DD is really unfriendly and I want to avoid it?

This question has an accepted answers - jump to answer


  • xtech_devxtech_dev Posts: 21Questions: 9Answers: 0
  • MSLtdMSLtd Posts: 56Questions: 5Answers: 4

    Hello @sjw01
    When you're using the DataTables date column you are limited to a very finite subset of formatting options, all of which I'm pretty sure, are in the format YYYY-MM-DD.

    If you are wishing to have a user friendly format, I'd recommend using the render attribute of the column declaration in your table initiation, to render an HTML5 Input of type: date (<input type="date" name="inputFieldName">) in the editor and pushing the information around yourself.

    In other news, I've had a play with the example and the date columns sort fine??

  • allanallan Posts: 48,896Questions: 1Answers: 7,129 Site admin

    Have a read over this blog post which goes into full details of date / time sorting in DataTables.


  • sjw01sjw01 Posts: 44Questions: 20Answers: 1

    @MSLtd It would appear that the column is sorted using the rendered data so we're back to square one. The columns definitely don't sort as required.

    @allan thanks, i'll take a look

  • sjw01sjw01 Posts: 44Questions: 20Answers: 1
    edited August 2018

    I read over the blog post and I implemented moment exactly as described.

    1. Included JS Files:

    <script type="text/javascript" src="//"></script>
    <script type="text/javascript" src="//"></script>

    1. Added column.type to the specified column:

    { title: "RO Date", type: "date" },

    1. Added formatting to dataTable

    $.fn.dataTable.moment( 'DD/MM/YY' );

    Still wont sort date columns ???

  • allanallan Posts: 48,896Questions: 1Answers: 7,129 Site admin
    Answer ✓

    You had:

    { title: "RO Date", type: "date" },

    Remove the type option. That is incorrectly forcing the data type. Allow DataTables to auto-detect the type.


Sign In or Register to comment.