I need help with a filter function on a table. For now I can Filter a table using Users input like this:
$(document).ready(function(){
$("#myInput").on( "keyup" ,function() {
var value = $(this).val().toLowerCase();
$("#myTable tr").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
This works also great but how can I filter the table with a selection of the users. So the user could select a option:
<select name="Filter" id="myInput">
<option id="myInput" value="error">John</option>
<option id="myInput" value="error">Warning</option>
</select>
and after he selected something I would filter after this. The table could looks like this:
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
<table>
<thead>
<tr>
<th>Log</th>
</tr>
</thead>
<tbody id="myTable">
<tr>
<td>dafsdfkj Error sdfkjlsdafj dsafjk</td>
</tr>
<tr>
<td>Waring dfadf adf</td>
</tr>
</tbody>
</table>
thx for help<3
Aucun commentaire:
Enregistrer un commentaire