Datatables with datetime sorting won't work with IE, Firefox and Safari, but works in Chrome only

Datatables with datetime sorting won't work with IE, Firefox and Safari, but works in Chrome only

rileystlrileystl Posts: 7Questions: 2Answers: 0

Here is the link to the code, and the output
http://live.datatables.net/lanudono/1/edit?html,css,output

I am using the moment-js and the datetime-moment.js plugins. In my HTML markup, I have datetime values in a certain
format (YYYY-MM-DD hh:mm:ss). And I am passing these values into the datetime-moment plugin for processing and converting to another format (DD/MM/YYYY HH:mm:ss)

The conversion happens nicely in Chrome. The sorting also works just fine in Chrome only. But I get an "invalid date" message when I view in Firefox, Safari and IE.
Please help!

Answers

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin

    I suspect that you need to tell moment what format the data is that you are passing in in the mRender function. At the moment it is probably just trying to use the browser defaults for parsing the date time since you haven't specified the input string format anyway (and Chrome is very forgiving). However, you are probably best refering to the moment documentation for this.

    Allan

  • rileystlrileystl Posts: 7Questions: 2Answers: 0

    Here is my code:
    http://live.datatables.net/xebudiwe/1/
    I have a large html table with over a 1000 rows. I have one datetime field and other not. I am using the datetime-moment library to sort the datetime column which is in the example format: "Thursday, March 5th 2015, 9:07:54 am"
    As can be seen from the output, the sorting appears to be working until "Thursday, March 5th 2015, 9:13:55 am" when I starting with earliest date in the past, which is Friday, January 23rd 2015, 3:27:57 pm.
    After March 5th 2015, 9:13:55 am, the sorting goes out of whack. The next entry I see is
    "Tuesday, January 27th 2015, 11:29:52 am" and listed are 4 entries for January 27th sorted correctly for these 4 values alone, and after "Tuesday, January 27th 2015, 11:32:02 am" the sorting goes all wrong again. The next entry I am seeing is: Wednesday, February 18th 2015, 3:34:50 pm. Why is this happening?
    I really need consistently sorted datetime sorted values.
    All I need is nicely sorted datetime values in ascending and descending order for all 1000+ entries, and if there are in some human readable format that is fine.

    Please help. Thanks in advance.

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin

    There are a number of errors:

    1. You have: "sType": "date-us", "aTargets": [ 0 ] on the first column. I'm not sure why when you want to be using the moment sorting.
    2. The format 'ddd, MMM Do YYYY, h:mm:ss a' is wrong - it should be 'dddd, MMMM Do YYYY, h:mm:ss a'
    3. There is a Javascript error on the page due to an undefined function
    4. No tbody element
    5. The date strings have a newline character and tabs in them. They should be removed, otherwise the exact parsing can't match.

    Allan

  • rileystlrileystl Posts: 7Questions: 2Answers: 0

    You said "You have: "sType": "date-us", "aTargets": [ 0 ] on the first column. I'm not sure why when you want to be using the moment sorting."
    If i understand you correctly, by having sType": "date-us", "aTargets": [ 0 ]", I am NOT using the moment sorting on column. Am I right then in understanding that these entries have to eliminated?

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin

    Absolutely bob on! Let the type detection that the plug-in creates detect the type automatically for you.

    Allan

  • rileystlrileystl Posts: 7Questions: 2Answers: 0

    I will implement your changes and let you know how it goes. And thanks much.

  • rileystlrileystl Posts: 7Questions: 2Answers: 0

    You said "The date strings have a newline character and tabs in them. They should be removed, otherwise the exacct parsing can't match"
    By date strings you are referring to the data in my table, right?
    For example: <td>Wednesday, February 18th
    2015, 4:35:04 pm</td>

    I did not see that..

  • rileystlrileystl Posts: 7Questions: 2Answers: 0

    It worked. I can post the code.
    The next thing I want to get working is: Currently my datetime entries are in the following form: For example, Friday, January 23rd 2015, 9:27:21 am
    I need this to become Fri Jan 23rd, 9:27:21 am.
    Is that possible?
    Please advise. Thanks so much.

  • allanallan Posts: 61,840Questions: 1Answers: 10,134 Site admin

    I need this to become Fri Jan 23rd, 9:27:21 am

    I don't see why not. Just update whatever it outputting your table data to output the format you want and modify the format that you are telling moment.js to use.

    Allan

This discussion has been closed.