I have a data structure here which i have divided into headers and the items. I am trying to apply a custom sort for which i have the logic down and i have created a method for it but i am not able to figure out how to apply that sort methods based on the name and grades individually. Here is a link to the codepen.
new Vue({
el: '#app',
data() {
return {
headers: [{
text: 'Name',
value: 'Name'
},
{
text: 'Grades',
value: 'grades'
},
],
labels: ['Andy', 'Max', 'John', 'Travis', 'Rick'],
Grades: [99, 72, 66, 84, 91]
}
},
computed: {
tableItems() {
let items = [],
this.labels.forEach((label, i) => {
let item = {}
item.name = label
item.grades = this.Grades[i]
items.push(item)
console.log(items)
})
return items
}
},
methods: {
sortBy(prop) {
this.tableItems.sort((a, b) => a[prop] < b[prop] ? -1 : 1)
}
}
})
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" rel="stylesheet" />
<div id="app">
<v-app id="inspire">
<v-container>
<v-layout>
<v-flex v-for="(header, i) in headers" :key="header.text" xs4 py-1>
<span>{{ header.text }}
<v-icon small @click="sortBy(this.labels)">arrow_upward</v-icon>
</span>
</v-flex>
<v-layout v-for="item in tableItems" :key="item.name">
<v-flex xs4 py-1>
<span>{{ item.name }}</span>
</v-flex>
<v-flex xs4 py-1>
<span>{{item.grades}}</span>
</v-flex>
</v-layout>
</v-layout>
</v-container>
</v-app>
</div>
Now while keeping the data structure and everything the way it is, how can i make the method on the v-icon work for grades and name individually?