sort on dates not working properly after upgrade to 1.10.5

sort on dates not working properly after upgrade to 1.10.5

apfzapfz Posts: 2Questions: 0Answers: 0

after updating from datatables 1.10.4 to 1.10.5 sorting on dates is not working properly anymore. For example descended sorting shows 31 Jan 2015 11:46 on top and 01 Jan 2015 14:11 at the bottom. A date like 08 Feb 2015 04:48 can be found somewhere in the middle. Looks like it is sorting on the first number only. Is this a bug?

Replies

  • allanallan Posts: 61,893Questions: 1Answers: 10,145 Site admin

    Can you link to a test case showing the issue please.

    It is worth noting that without a plug-in the only reliable data format for sorting is ISO8601 since DataTables uses the built in Date.parse in Jvascript which varies a huge amount by browser.

    Allan

  • richard_dernrichard_dern Posts: 3Questions: 0Answers: 0

    I have the exact same problem.

    Here is how I reproduce it.

    I have an empty table with regular thead, containing a column named "Date". I initialize DataTables:

    var dt = $('#mytable").DataTable();
    

    I load rows with a standard jQuery request, then:

    dt.rows().remove();
    dt.rows.add(myrows);
    dt.draw();
    

    Cells containing dates have a data-sort attribute, containing ISO date. myrows is simply an array of jQuery tr objects.

    The table display is fine, I can order on other columns but containing dates.

  • allanallan Posts: 61,893Questions: 1Answers: 10,145 Site admin

    Cells containing dates have a data-sort attribute, containing ISO date. myrows is simply an array of jQuery tr objects.

    DataTables will detect data attributes only on initialisation. See this GitHub discussion on the topic, particularly my last comment for how to resolve it.

    Allan

  • richard_dernrichard_dern Posts: 3Questions: 0Answers: 0

    Ok. Thank you for answer.

    However, I just tried using the documented ajax method, where the server sends back an array of objects. Each object looks like this:

    {
        title: "my title"
        date: {
            display: "18/02/2015 15:10:25",
            raw_value: "2015-02-18 15:10:25"
        }
    }
    

    The column is initialized with the render attribute:

    'render': {
        '_': 'display',
        'sort': 'raw_value'
    )
    

    And it still doesn't sort dates correctly. Am I missing something else ?

  • allanallan Posts: 61,893Questions: 1Answers: 10,145 Site admin

    With that code the type detection will be running on the display property. You will want to add:

    'type': 'raw_value'
    

    to your object as well.

    Allan

  • richard_dernrichard_dern Posts: 3Questions: 0Answers: 0

    Ok, now it works. Excellent, thank you very much !

This discussion has been closed.