Created
July 6, 2012 17:11
-
-
Save Tomalak/3061389 to your computer and use it in GitHub Desktop.
A custom textExtraction function for jQuery tablesorter that allows better sorting for accented characters and dates in dd.mm.yyyy format. Primarily targeted at German text; might work well for other languages.
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
// Details: StackOverflow (http://stackoverflow.com/a/614397/18771) | |
// License: cc-by-sa (http://creativecommons.org/licenses/by-sa/3.0/) | |
// Extends: jQuery Tablesorter 2.0+ (http://tablesorter.com) | |
// ------------------------------------------------------------------- | |
// file encoding must be UTF-8! | |
function getTextExtractor() | |
{ | |
return (function() { | |
var patternLetters = /[öäüÖÄÜáàâéèêúùûóòôÁÀÂÉÈÊÚÙÛÓÒÔß]/g; | |
var patternDateDmy = /^(?:\D+)?(\d{1,2})\.(\d{1,2})\.(\d{2,4})$/; | |
var lookupLetters = { | |
"ä": "a", "ö": "o", "ü": "u", | |
"Ä": "A", "Ö": "O", "Ü": "U", | |
"á": "a", "à": "a", "â": "a", | |
"é": "e", "è": "e", "ê": "e", | |
"ú": "u", "ù": "u", "û": "u", | |
"ó": "o", "ò": "o", "ô": "o", | |
"Á": "A", "À": "A", "Â": "A", | |
"É": "E", "È": "E", "Ê": "E", | |
"Ú": "U", "Ù": "U", "Û": "U", | |
"Ó": "O", "Ò": "O", "Ô": "O", | |
"ß": "s" | |
}; | |
var letterTranslator = function(match) { | |
return lookupLetters[match] || match; | |
} | |
return function(node) { | |
var text = $.trim($(node).text()); | |
var date = text.match(patternDateDmy); | |
if (date) | |
return [date[3], date[2], date[1]].join("-"); | |
else | |
return text.replace(patternLetters, letterTranslator); | |
} | |
})(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment