I have a script, it shows database-rows as list-group with a searchbar. Yes, it works.
But the database has about 10.000 rows. I want to show only the first 5 rows in the list-group, but I want to use for search all rows.
<ul class="list-group" id="myList">
<?
if ($result = $conn->query($sql)) {
/* fetch object array */
while ($row = $result->fetch_row()) {
if ($show_row < 6) echo "<li class='list-group-item'>$row[0]</li>"; // show row
if ($show_row > 5) echo "<li class='list-group-item'>$row[0]</li>"; // hide row, but use it for search
$show_row++;
}
}
?>
</ul>
<script>
$(document).ready(function(){
$("#myInput").on("keyup", function() {
var value = $(this).val().toLowerCase();
$("#myList li").filter(function() {
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
});
});
});
</script>
Thanks for answers ;-)
The easiest thing to do with what you have is use CSS
display:noneon rows that you do not want to initially display, then reset to the original state if there is no input. I would also pre-digest the searchable values and insert them as data attributes in thelitags, so that you don't have to calculate that in real time for each item during the search.