Table has two columns Name, Age. Searching works by name. As you type the name of user the table will trim down to the specific user name.
But I want it to be filtered by age using a comparison operator < or >.
Html
<div id="demo" class="container">
<div class="row">
<div class="col-md-6">
<input v-model="search" class="form-control" placeholder="Username to search">
</div>
<div class="col-md-1">
<select class="form-control" v-model="searchOperator">
<option value=">">></option>
<option value="<"><</option>
</select>
</div>
<div class="col-md-5">
<input v-model="searchName" class="form-control" placeholder="Age">
</div>
</div>
<table class="table table-striped">
<thead>
<tr>
<th v-repeat="column: columns">
<a href="#" v-on="click: sortBy(column)" v-class="active: sortKey == column">
{{ column | capitalize }}
</a>
</th>
</tr>
</thead>
<tbody>
<tr v-repeat="users | filterBy search | orderBy sortKey reverse">
<td>{{ name }}</td>
<td>{{ age }}</td>
</tr>
</tbody>
</table>
</div>
Vue :
new Vue({
el: '#demo',
data: {
sortKey: 'name',
reverse: false,
searchName: '',
searchOperator: '',
searchAge: '',
columns: ['name', 'age'],
newUser: {},
users: [
{ name: 'John', age: 50 },
{ name: 'Jane', age: 22 },
{ name: 'Paul', age: 34 }
]
},
methods: {
sortBy: function(sortKey) {
this.reverse = (this.sortKey == sortKey) ? ! this.reverse : false;
this.sortKey = sortKey;
}
}
});
What is the best approach to achieve this? I tried but nothing seem to be working.