Answer the question
In order to leave comments, you need to log in
How to filter table rows in vuejs?
When you select a table row, you need to hide the rest of the rows, while pressing the button in the row again - you need to return it as it was.
<template>
<div class="container-fluid" id="searchResult">
<div class="row">
<div class="col s12">
<div class="card-panel grey lighten-5 z-depth-1">
<table class="highlight">
<tbody>
<tr v-for="(val, key, index) in objSearch">
<td>{{ val.name }}</td>
<td>{{ val.lastname }}</td>
<td>
<a class="waves-effect waves-light btn>Выбрать</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
objSearch: {
0: {
name: 'Сергей',
lastname: 'Иванович',
},
1: {
name: 'Андрей',
lastname: 'Петрович',
}
},
}
}
}
</script>
Answer the question
In order to leave comments, you need to log in
Let's add a property to the component that will represent the selected row:
data: () => ({
selected: null,
...
}),
<tr v-for="(n, i) in (selected || objSearch)">
@click="selected = selected ? null : { [i]: n }"
.hidden {
visibility: hidden;
}
<tr
v-for="(n, i) in objSearch"
:class="{ hidden: selected !== null && selected !== i }"
>
@click="selected = selected === null ? i : null"
<tr v-for="(val, key, index) in objSearch | filterBy current">
<td>{{ val.name }}</td>
<td>{{ val.lastname }}</td>
<td><a class="waves-effect waves-light btn" @click="Choose(val)">Выбрать</a></td>
</tr>
{
data: function(){
render: {
current: '',
}
}
...
methods: {
Choose: function(val){
this.current = val;
}
}
...
}
<tr v-for="(val, key, index) in objSearch | filterBy current in 'id'">
<td>{{ val.name }}</td>
<td>{{ val.lastname }}</td>
<td><a class="waves-effect waves-light btn" @click="Choose(val)">Выбрать</a></td>
</tr>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question