A Pen by Alberto Vieira de Lima on CodePen.
Last active
September 6, 2018 14:56
-
-
Save avlima/c946d0f0a1c2736b7ce46256dfe03c71 to your computer and use it in GitHub Desktop.
sort the records containing accents angular-datatables
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
<div ng-app="datatablesSampleApp"> | |
<div ng-controller="SampleCtrl as showCase"> | |
<table datatable="" dt-options="showCase.dtOptions" dt-columns="showCase.dtColumns" class="row-border hover"></table> | |
</div> | |
</div> |
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
jQuery.extend( 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; | |
}, | |
"portugues-asc": function ( a, b ) { | |
return ((a < b) ? -1 : ((a > b) ? 1 : 0)); | |
}, | |
"portugues-desc": function ( a, b ) { | |
return ((a < b) ? 1 : ((a > b) ? -1 : 0)); | |
} | |
} ); | |
angular.module('datatablesSampleApp', ['datatables', 'datatables.fixedheader']) | |
.controller('SampleCtrl', SampleCtrl); | |
function SampleCtrl($q, DTOptionsBuilder, DTColumnBuilder) { | |
var vm = this; | |
vm.dtOptions = DTOptionsBuilder.fromFnPromise(function() { | |
var defer = $q.defer(); | |
defer.resolve([ | |
{name: 'Álberto'}, | |
{name: 'Alberto Lima'}, | |
{name: 'Beto'}, | |
{name: 'Dwarf'}, | |
{name: 'Hector'}, | |
{name: 'Hígor'}, | |
{name: 'Wellington'} | |
]); | |
return defer.promise; | |
}); | |
vm.dtColumns = [ | |
DTColumnBuilder.newColumn('name').withTitle('Name').withOption("type", "portugues") | |
]; | |
} |
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="http://code.jquery.com/jquery-1.10.1.min.js"></script> | |
<script src="//cdn.datatables.net/1.10.8/js/jquery.dataTables.min.js"></script> | |
<script src="https://cdn.datatables.net/fixedheader/3.1.2/js/dataTables.fixedHeader.min.js"></script> | |
<script src="http://code.angularjs.org/1.3.13/angular.js"></script> | |
<script src="https://rawgithub.com/l-lin/angular-datatables/dev/dist/angular-datatables.min.js"></script> | |
<script src="https://rawgithub.com/l-lin/angular-datatables/dev/dist/plugins/fixedheader/angular-datatables.fixedheader.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="//cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css" rel="stylesheet" /> | |
<link href="https://cdn.datatables.net/fixedheader/3.1.2/css/fixedHeader.dataTables.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment