I made an input search to filter a list of users that is called with PHP. I'm trying to implement in Vue.js the filter so that when I search the name, the user appears filtered in the list.
Here is the searchbar HTML:
<div class="row" id="toprow">
<div class="col-md-6">
<div id="titlerow1">Users</div>
</div>
<div class="col-md-6">
<input class="searchbar" id="search1" placeholder="Search..."></input>
</div>
</div>
The users list HTML:
<div id="users" name="users">
<?php if(!empty($user))
{
foreach($user as $value)
{
?>
<div class="row oddEven usersElements userid" id=<?php echo $value->id;?> style="margin-top: -1vw;">
<div v-on:click="displayAgregators(<?php echo $value->id;?>)" class="col-md-10">
<span id="items<?php echo $value->id;?>"><?php echo ucfirst($value->username);?></span>
</div>
<div class="col-md-2">
<div class="colorsByUser" :style="{backgroundColor: randomColor()}"></div>
</div>
</div>
<?php }
}?>
</div>
Before it was in jQuery, here is the code:
$('#search1').keyup(function() {
var string1 = $(this).val().toLowerCase();
console.log("str1=" + string1);
$(".usersElements").each(function(index) {
var string = $(this).attr('id');
var string2 = $('#' + string).text().toLowerCase();
console.log("str2=" + string2);
var valtest = string2.indexOf(string1);
console.log("index value:" + valtest);
if (valtest >= 0) {
$('#' + string).show();
} else {
$('#' + string).hide();
}
});
});
I hope you guys can help! :)