Created
February 14, 2014 22:12
-
-
Save Dekryptid/9010494 to your computer and use it in GitHub Desktop.
jquery.dataTables - U.S. Date Sort Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.extend($.fn.dataTableExt.oSort, { | |
"date-us-pre": function (a) { | |
var b = a.match(/(\d{1,2})\/(\d{1,2})\/(\d{2,4})/), | |
month = b[1], | |
day = b[2], | |
year = b[3]; | |
if (year.length == 2) { | |
if (parseInt(year, 10) < 70) year = '20' + year; | |
else year = '19' + year; | |
} | |
if (month.length == 1) month = '0' + month; | |
if (day.length == 1) day = '0' + day; | |
var tt = year + month + day; | |
return tt; | |
}, | |
"date-us-asc": function (a, b) { | |
return a - b; | |
}, | |
"date-us-desc": function (a, b) { | |
return b - a; | |
} | |
}); | |
$.fn.dataTableExt.aTypes.unshift(function (sData) { | |
if (sData !== null && sData.match(/\d{1,2}\/\d{1,2}\/\d{2,4}/)) { | |
return 'date-us'; | |
} | |
return null; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment