0
I created a input[type='text']
and a table HTML
, and by entering a term in the field input[type='text']
the code I queried strings within all <tr><td></td></tr>
and hides what does not exist in the terms, the goal is to filter table results to locate a record quickly.
<div class="row">
<form class="form-inline" id="searchForm" onSubmit="return false;">
<div class="form-group">
<input type="text" id="searchItem" class="form-control" placeholder="Buscar por termos na tabela">
</div>
</form>
</div>
<div class="row">
<table class="table table-bordered table-striped">
<thead>
<tr>
<td>#ID</td>
<td>Prévia</td>
<td>Titular</td>
<td>Relatório</td>
</tr>
</thead>
<tbody>
<tr>
<td>948576</td>
<td><img class='LazyLoad' src='' data-url='./uploads/thumb/{[TRACK_IMG]}'></td>
<td>João Nascimento Alcântara</td>
<td><button>Gerar</button></td>
</tr>
<tr>
<td>857541</td>
<td><img class='LazyLoad' src='' data-url='./uploads/thumb/{[TRACK_IMG]}'></td>
<td>Joao de Nascimento Alcantara</td>
<td><button>Gerar</button></td>
</tr>
</tbody>
</table>
</div>
And Javascript:
<script>
$(document).ready(function(){
$("#searchItem").on('keyup', function() {
var conta = $("#searchItem").val();
if(conta.length == 0) {
$("table.table tbody tr").removeAttr('style');
}
});
$('#searchItem').on('keyup', function(e){
e.preventDefault();
var input = document.getElementById("searchItem");
var conta = $("#searchItem").val();
if(conta.length >= 3) {
var filter = input.value.toLowerCase();
var nodes = $("table.table tbody tr");
for (i = 0; i < nodes.length; i++) {
if (nodes[i].innerText.toLowerCase().includes(filter)) {
} else {
$(nodes[i]).attr('style','display:none');
}
}
}
});
});
</script>
What happens is that if I type Joao (without accent) the code does not recognize John and so hides the line of the record, I want the code to recognize John for Joao and John for John, I could not.
Perfect, adapted and working, thank you so much for everything once again.
– ElvisP
I speak young. Q thing we are there
– Sam
Just for the record, I read and understood how the function works and the adaptation of the rsrs code was worth
– ElvisP
Perhaps the use of . Trim() is unnecessary. I think you can remove it
– Sam
removed, handle unnecessary space on output, it would not even be necessary.
– ElvisP