Good, I'm trying to perform a search on a php table.
This is the code with which I show my table:
<div class="form-group">
<label for="search">Buscar:</label>
<div class="input-group col-sm-6">
<input type="text" REQUIRED class="form-control" id="search" placeholder="Ingresar Nombre">
</div>
</div>
<table class="table table-bordered table-hover">
<thead>
<tr bgcolor="#AFDDEC">
<th>Cliente</th>
<th>Tipo Documento</th>
<th>Documento</th>
<th>Direccion</th>
</tr>
</thead>
<tbody>
<?php
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo '<tr><td>'.$row["nombre"].' '.$row["apellidos"].
'</td><td>'.$row["tipo_doc"].
'</td><td>'.$row["dni"].
'</td><td>'.$row["direccion"].
'</td></tr>';
}
} else {
echo "0 results";
}
?>
</tbody>
</table>
And here the fragment of jquery, with which I thought I could implement it:
var $rows = $('.table tr');
$('#search').keyup(function() {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
$rows.show().filter(function() {
var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(val);
}).hide();
});
But the code simply does not do anything. Any suggestions to be able to search my table? Sorry for the inconvenience but I'm new to this. Thanks in advance.