Last active
March 15, 2016 14:55
-
-
Save demonio/011e4d6937d16e69834e to your computer and use it in GitHub Desktop.
Snippet para filtrar filas o elementos ignorando acentos y mayúsculas (con un input.js-filter + data-to a una lista o tabla).
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
$(function() | |
{ | |
/* INPUT LIVE FILTER */ | |
$('body').on( 'keyup', '.js-filter', function() | |
{ | |
var item = $(this).data('to'); | |
var search = $(this).val(); | |
$(item).hide(); | |
$(item+":icontains('"+search+"')").show(); | |
}); | |
}); | |
/* INPUT LIVE FILTER ACCENTS */ | |
replaceAccents = function(q) { | |
q = q.replace(/[eéèêëEÉÈÊË]/gi,'[eéèêëEÉÈÊË]'); | |
q = q.replace(/[aàâäAÀÁÂÃÄÅÆ]/gi,'[aàâäAÀÁÂÃÄÅÆ]'); | |
q = q.replace(/[cçC]/gi,'[cçC]'); | |
q = q.replace(/[iïîIÌÍÎÏ]/gi,'[iïîIÌÍÎÏ]'); | |
q = q.replace(/[oôöÒÓÔÕÖ]/gi,'[oôöÒÓÔÕÖ]'); | |
q = q.replace(/[uüûUÜÛÙÚ]/gi,'[uüûUÜÛÙÚ]'); | |
q = q.replace(/[yYÿÝ]/gi,'[yYÿÝ]'); | |
return q; | |
}; | |
/* INPUT LIVE FILTER IS SENSITIVE CASE */ | |
jQuery.expr[':'].icontains = function(a, i, m) | |
{ | |
var q = jQuery(a).text(); | |
return replaceAccents(q).toUpperCase().indexOf( replaceAccents(m[3]).toUpperCase() ) >= 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment