rodrigobertin
8/8/2013 - 5:51 PM

Filtrar campos en tabla

Filtrar campos en tabla

<script>
  var searchOnTable = function() {
  var table = $('table');
  var value = this.value;
  table.find('tr').each(function(index, row) {
    var allCells = $(row).find('td');
    if(allCells.length > 0) {
      var found = false;
      allCells.each(function(index, td) {
        var regExp = new RegExp(value, 'i');
        if(regExp.test($(td).text())) {
          found = true;
          return false;
        }
      });
      if (found == true) $(row).show();
      else $(row).hide();
    }
  });
};

$(function(){
  $('#filter').keyup(searchOnTable);
});
</script>

//para el buscador
<input type="text" id="filter" placeholder="Filtrar">