Created
September 29, 2022 03:24
-
-
Save rah00l/227a72a3f7a876ac91fdad867058507b to your computer and use it in GitHub Desktop.
Bootstrap Filters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<h2>Filterable Table</h2> | |
<p>Type something in the input field to search the table for first names, last names or emails:</p> | |
<input class="form-control" id="myInput" type="text" placeholder="Search.."> | |
<br> | |
<table class="table table-bordered table-striped"> | |
<thead> | |
<tr> | |
<th>Firstname</th> | |
<th>Lastname</th> | |
<th>Email</th> | |
</tr> | |
</thead> | |
<tbody id="myTable"> | |
<tr> | |
<td>John</td> | |
<td>Doe</td> | |
<td>[email protected]</td> | |
</tr> | |
<tr> | |
<td>Mary</td> | |
<td>Moe</td> | |
<td>[email protected]</td> | |
</tr> | |
<tr> | |
<td>July</td> | |
<td>Dooley</td> | |
<td>[email protected]</td> | |
</tr> | |
<tr> | |
<td>Anja</td> | |
<td>Ravendale</td> | |
<td>[email protected]</td> | |
</tr> | |
<tr> | |
<td>John</td> | |
<td>Doe</td> | |
<td>[email protected]</td> | |
</tr> | |
</tbody> | |
</table> | |
<p>Note that we start the search in tbody, to prevent filtering the table headers.</p> | |
</div> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/js/bootstrap.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment