default sort on timestamps

default sort on timestamps

loukinglouking Posts: 259Questions: 52Answers: 0
edited May 2015 in Free community support

I am using a wordpress plugin https://wordpress.org/plugins/inline-google-spreadsheet-viewer/ which displays google docs inline using datatables. I have some datatables experience with the older version in an application I developed. Yeah, yeah, I'll get around to updating next time I crack that application open.

But I digress...

What I would like to know now, is if the table at http://sandbox.steeplechasers.org/membership/brag-corner/ will sort properly if order="[[0,'desc']]".

I'd rather know now than wait until October to find out datatables is not recognizing the timestamp column as anything other than text. https://datatables.net/reference/option/columns.type says date is automatically detected, but will the time after the date confuse the package?

Replies

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin

    The date formats detected are based on the Date.parse() method built into Javascript. ISO8601 is the only date / time format that is guaranteed to work correctly (and even then, it was only a recent version of the specs that mandated that).

    Each browser supports different formats - Chrome in particular tries darn hard to make it work, other browsers not so much.

    Take a gander at this blog post for more details and a possible solution.

    Allan

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin

    To answer your direct question - Chrome and Firefox are currently detected your first column as a date column. I haven't tried your page in IE.

    Allan

  • loukinglouking Posts: 259Questions: 52Answers: 0
    edited May 2015

    Thanks. I'm not sure how much control I can impose from the outside of how the wordpress plugin is working. I'm hoping datatables just figures it out, without the need for me to add javascript plugin and code for that. (Although I might be able to trick the WP plugin developer into adding this if necessary. ;) )

    Having said that, what did you look at to see that Chrome and Firefox are detecting a date column? I assume you mean "datatables when run within Chrome and Firefox is detecting a date column", right? Or maybe you are looking something more basic within the browsers.

    MTA: Are you just running Date.parse('<my format>') in the console?

    I can do additional testing (e.g., IE, Safari), although I'm not quite sure how to test smartphone behavior if this is browser dependent.

  • loukinglouking Posts: 259Questions: 52Answers: 0

    Date.parse('5/13/2015 16:24:32') seems to work in IE and Safari, with Date.parse('5/13/2015 16:24:31') giving a different result. I am going to guess that since this works in all the major desktop browsers it also works in the smartphone browsers.

    I ran IE in IE7 emulation mode, and it still worked, although I am not sure the console behavior is emulated. Yeah, I can google that.

    Thanks for the tips.

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin

    Having said that, what did you look at to see that Chrome and Firefox are detecting a date column?

    Use the debugger and then in the tables tab click the 'Columns' option. It will show you the type that DataTables has detected.

    One thing to watch out for with xx/yy/zzzz format is that xx and yy can be ambiguous for which is day and which is month. Date.parse() will use the browser's locale settings so different computers in different parts of the world will give different results.

    Using a plug-in like the one I mentioned or ISO8601 are the only sure fire way of making it work.

    Allan

  • loukinglouking Posts: 259Questions: 52Answers: 0

    Good point.

    Thanks again!

This discussion has been closed.