1) Call bootstrap.min.js and CSS
2) make table & one input
3) jQuery keyup function which is useful when start typing it check in table, for each character check using keyup function.
4) filter function default in jQuery
<html lang="en">
<head>
<title>Bootstrap filter table.</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container mt-3">
<input class="form-control" id="valuetosearch" type="text" placeholder="Search..">
<table class="table table-bordered">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody id="searchintotable">
<tr>
<td>kumar</td>
<td>sample</td>
<td>abc@example.com</td>
</tr>
<tr>
<td>check</td>
<td>hi</td>
<td>check@mail.com</td>
</tr>
<tr>
<td>learn</td>
<td>joy</td>
<td>lear@greatstuff.com</td>
</tr>
<tr>
<td>blog</td>
<td>where</td>
<td>blog@test.com</td>
</tr>
</tbody>
</table>
</div>
<script>
$(document).ready(function(){
$("#valuetosearch").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#searchintotable tr").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
</script>
</body>
</html>
No comments:
Post a Comment