dd-mon-yyyy IE shim

dd-mon-yyyy IE shim

jhfrenchjhfrench Posts: 15Questions: 0Answers: 0
edited May 2013 in Plug-ins
The organization I support dictates that all dates will be shown in dd-MON-yyyy format (10-SEP-2006, 08-MAY-2013).

When run on Chrome, dataTables correctly recognizes this pattern as a date.
Unfortunately, we also have to support IE7. Thankfully I came across abbottmw's sorting function for my pattern (http://datatables.net/forums/discussion/1933/dd-mon-yyyy-date-format/p1#Comment_8401).

My question is, what is the syntax for using abbottmw's sorting function for only IE, but not for Chrome? Is there a way I can do the sorting declaration conditionally?

Please see http://jsfiddle.net/jhfrench/zpWWa/ for an example dataset.

Replies

  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    Best way would be to do a feature detection. Check 'manually' (i.e. in code) if Date.parse() reads the format type. If it doesn't then use the plug-in, if it does, don't.

    Allan
  • jhfrenchjhfrench Posts: 15Questions: 0Answers: 0
    Within the plugin code, or within the `dataTable();` call?
  • jhfrenchjhfrench Posts: 15Questions: 0Answers: 0
    Is there a way to shim IE's JavaScript at a higher level? DataTable's ability to detect data types is really powerful--it means I can call it on all types of tables without needing to define for each the data types. Shimming at a higher level would keep that ability in play for me.
  • jhfrenchjhfrench Posts: 15Questions: 0Answers: 0
    PS--sending a little something your way to thank you for your software and the help. Curiously, amazon.co.uk won't let me add a note, so I'm mentioning it here so you'd know you're appreciated.
  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    That's awesome - thank you!

    > Is there a way to shim IE's JavaScript at a higher level?

    As in replace the Date object? You probably could, but I suspect there is a belly full of hurt in that direction...

    > Within the plugin code, or within the `dataTable();` call?

    I'd suggest doing the detection just before the `dataTable()` call, and then using the result in the initialisation object. You'd set sType to point to the plug-in, or have it use `null` (for Chrome etc).

    The other option is to always use a plug-in, optionally with feature detection inside it. Additionally you could possibly use a type detection plug-in to perform this action.

    Out of interest, what is the date format that you are using?

    Allan
  • jhfrenchjhfrench Posts: 15Questions: 0Answers: 0
    The organization I support dictates that all dates will be shown in dd-MON-yyyy format (10-SEP-2006, 08-MAY-2013). Chrome supports it "out of box". IE doesn't.
  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    Neither does Firefox apparently. You'll definitely want feature detection rather than just looking for IE.

    [code]
    var canParse = ! isNaN( Date.parse('08-MAY-2013') );
    [/code]

    Allan
  • jhfrenchjhfrench Posts: 15Questions: 0Answers: 0
    Hey Allan--check out http://stackoverflow.com/a/16614898/1430996 for my solution(s).

    If you're inclined to incorporate it, I can contribute the "dd-MMM-YYYY" sorting algorithm to the Github project (via a pull request). If so, in which folder should it (http://appliedinter.net/Workstream/common_files/js/dataTable_shim_dd-MMM-yyyy.js) be added? DataTables\examples\plug-ins?
  • allanallan Posts: 61,722Questions: 1Answers: 10,108 Site admin
    Excellent stuff - nice one.

    If you could issue a pull request, that would be great. It should go into here: https://github.com/DataTables/Plugins/tree/master/sorting

    Allan
  • jhfrenchjhfrench Posts: 15Questions: 0Answers: 0
    Changed the name to match other date sorting plugins and commented to match other files too. Created pull request 18.
This discussion has been closed.