I'm using the below function to do a "live" search on a table. The problem is that I want it to bring data into all the columns, and it's currently only bringing the first.
function pesquisaTabela() {
// Declare variables
var input, filter, table, tr, td, i;
input = document.getElementById("search");
filter = input.value.toUpperCase();
table = document.getElementById("dados");
tr = table.getElementsByTagName("tr");
console.log("ssss"+tr.length);
// Loop through all table rows, and hide those who don't match the search query
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[0];
if (td) {
if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
console.log(tr[i]);
} else {
tr[i].style.display = "none";
}
}
}
}
Table
<table class"table-highlight" id="dados">
<thead>
<tr>
<th data-field="id">Item</th>
<th data-field="numero">Número de Rastreamento</th>
<th data-field="data">Enviado em</th>
<th data-field="status">Status</th>
</tr>
</thead>
<tbody>
<tr>
<td>Pacote 01</td>
<td><a class="waves-effect waves-light btn" href="#modal1">BR021WMR000016437462</a></td>
<td>20/01/2017</td>
<td><span>Em trânsito</span></td>
</tr>
<tr>
<td>Pacote 02</td>
<td><a class="waves-effect waves-light btn" href="#modal1">SP021WMR000016437462</a></td>
<td>15/01/2017</td>
<td><span>Entregue</span></td>
</tr>
<tr>
<td>Pacote 03</td>
<td><a class="waves-effect waves-light btn" href="#modal1">CR021WMR000016437462</a></td>
<td>20/01/2017</td>
<td><span>Cancelado</span></td>
</tr>
</tbody>
</table>