-1
I made a table in html with 5 columns and more than 300 lines. In this table I put a <th>
with two lines, where in the first I have the titles of each column and in the second a field for searches in the table. As the person is typing the table is being updated with the results obtained. the code I used was this:
$(function(){
$("#tabela input").keyup(function(){
var index = $(this).parent().index();
var nth = "#tabela td:nth-child("+(index+1).toString()+")";
var valor = $(this).val().toUpperCase();
$("#tabela tbody tr").show();
$(nth).each(function(){
if($(this).text().toUpperCase().indexOf(valor) < 0){
$(this).parent().hide();
}
});
});
$("#tabela input").blur(function(){
$(this).val("");
});
});
This table I left without edges and not to be too simple I decided to leave it zebrada, but when performing the consultations this zebrado disappears. For example, if my search returns 20 results, instead of 10 columns with color and 10 without color intercalated, several rows with color together will appear leaving a gray block in the middle of the table.
I was using CSS to make the zebra and I couldn’t get it to update with the query or using prayer. In my internet searches I found some things and tried to implement but nothing worked, now I’m using the own javascript to make zebra using this code:
$(function(){
$("tr:nth-child(odd)").css("background-color", "#DCDCDC");
$("tr:nth-child(odd)").css("color", "black");
$("tr:nth-child(odd)").css("font-weight", "bold");
});
In short I just want that when performing the search the table remains zebrad. It is possible to do this?
I tried to do it that way and it didn’t work out. The problem keeps appearing I will post as it was the code changed because I may be making some error in the function call. I don’t know very well js, I looked at the documentation on the web but I still can’t identify what I might be doing wrong.
– Humberto Faria