Skip to content

Instantly share code, notes, and snippets.

@demonio
Last active March 15, 2016 14:55
Show Gist options
  • Save demonio/011e4d6937d16e69834e to your computer and use it in GitHub Desktop.
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).
$(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