I have set up a select
element in my HTML
code and I am looking to give users the option to sort a table based on the selected option values.
The information I need to organize (which consists of many objects) is shown below:
https://i.sstatic.net/d0p4Q.png
I am monitoring a select element that has a v-model value called "sort":
watch: {
search: function (val) {
if (val.length === 0) return this.filtered = this.affiliates;
this.filtered = this.affiliates.filter(function (cont) {
return cont.shop_name.toLowerCase().indexOf(val.toLowerCase()) >= 0 || cont.app_name.toLowerCase().indexOf(val.toLowerCase()) >= 0;
});
},
sort: function (val) {
console.log(this.filtered);
},
How can I arrange the objects
based on the selected sorting value?
The data is stored in the variable this.filtered
I aim to sort by the following values:
<select v-model="sort">
<option value="date_installed">Latest</option>
<option value="status">Status</option>
<option value="share">Share</option>
</select>