A Pen by Alberto Vieira de Lima on CodePen.
Created
April 11, 2018 03:45
-
-
Save avlima/6cbd559aa80acc32de9f07070abbd0b5 to your computer and use it in GitHub Desktop.
how to sort records containing accents
This file contains hidden or 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
<table id="example"> | |
</table> |
This file contains hidden or 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
$(document).ready(function() { | |
var data = [ | |
["Alberto Lima"], | |
["Dwarf"], | |
[ "Garrett Winters"], | |
["Álberto"], | |
[ "Hector"], | |
[ "Hígor" ], | |
[ "Wellington" ], | |
["Beto"] | |
]; | |
$('#example').DataTable( { | |
"aaData": data, | |
"aoColumns": [ | |
{ | |
"sType": "portugues", | |
"title": "Name" | |
}, | |
], | |
"aaSorting": [[ 0, "asc" ]], | |
} ); | |
} ); | |
jQuery.fn.dataTableExt.oSort["portugues-asc"] = function (a, b) { | |
return ((a < b) ? -1 : ((a > b) ? 1 : 0)); | |
} | |
jQuery.fn.dataTableExt.oSort["portugues-pre"] = function (data) { | |
var a = 'a'; | |
var e = 'e'; | |
var i = 'i'; | |
var o = 'o'; | |
var u = 'u'; | |
var c = 'c'; | |
var special_letters = { | |
"Á": a, "á": a, "Ã": a, "ã": a, "À": a, "à": a, | |
"É": e, "é": e, "Ê": e, "ê": e, | |
"Í": i, "í": i, "Î": i, "î": i, | |
"Ó": o, "ó": o, "Õ": o, "õ": o, "Ô": o, "ô": o, | |
"Ú": u, "ú": u, "Ü": u, "ü": u, | |
"ç": c, "Ç": c | |
}; | |
for (var val in special_letters) | |
data = data.split(val).join(special_letters[val]).toLowerCase(); | |
return data; | |
}; | |
jQuery.fn.dataTableExt.oSort["portugues-asc"] = function (a, b) { | |
return ((a < b) ? -1 : ((a > b) ? 1 : 0)); | |
} |
This file contains hidden or 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
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script> |
This file contains hidden or 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
<link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment