0
I have a table and I’m making a filter worked, but when I put the input inside the div to align can not filter, even takes 1 letter but does not filter more.
<script type="text/javascript">
$(function(){
$("#inputUserfilter").keyup(function(){
var index = $(this).parent().index();
console.log('test');
var nth = "#tableUser td:nth-child("+(index+1).toString()+")";
var valor = $(this).val().toUpperCase();
$("#tableUser tbody tr ").show();
$(nth).each(function(){
if($(this).text().toUpperCase().indexOf(valor) < 0){
$(this).parent().hide();
}
});
});
$("#inputUserfilter").blur(function(){
$(this).val("");
});
});
</script>
<div class="styleinput" >
<label>Filtrar: </label>
<input type="text" id="inputUserfilter"/>
</div>
Try changing
$(this).parent().index()
for$(this).closest("td").index()
– Sam
[sopt] makes use of the structure of questions and answers in which questions should be questions and answers should be answers. If you found the solution to the problem, post as reply, not as a question edit. Also remember to explain what the problem was and why the code solved it. Posting only a single piece of code is unlikely to be useful to the community and may receive negative votes.
– Woss